-
Notifications
You must be signed in to change notification settings - Fork 0
/
learn_git.html
151 lines (122 loc) · 6.32 KB
/
learn_git.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Learn Git</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Learn Git - A Step-by-Step Guide</h1>
<p>This guide covers the basics of Git, from installation to making changes. Follow these steps to improve your
version control skills.</p>
<ol>
<li><strong>Install Git:</strong> Download and install Git for your operating system from the official website:
<a href="https://git-scm.com/downloads" target="_blank">Git SCM Downloads</a>.
</li>
<li><strong>Basic Configuration:</strong> Set up your username and email in Git by running these commands in the
terminal:
<pre><code>git config --global user.name "Your Name"</code></pre>
<pre><code>git config --global user.name "Zahid"</code></pre>
<pre>Add your email address:</pre>
<pre><code>git config --global user.email "[email protected]"</code></pre>
<pre><code>git config --global user.email "[email protected]"</code></pre>
This links your commits to your identity.
</li>
<li><strong>Initialize a Git Repository:</strong> Start a Git repository in your project folder:
<pre><code>git init</code></pre>
</li>
<li><strong>Check Repository Status:</strong> View the status of your repository and track changes:
<pre><code>git status</code></pre>
</li>
<li><strong>Add a Remote Repository:</strong> Link your local repository to a remote repository (e.g., GitHub):
<pre><code>git remote add origin repository-url</code></pre>
<pre><code>git remote add origin https://github.com/username/repository.git</code></pre>
</li>
<li><strong>Stage Files for Commit:</strong> Add files to the staging area for committing. You can add specific
files or all changed files:
<pre><code>git add filename</code></pre>
<pre><code>git add 'learn_git.html'</code></pre>
<pre><code>git add .</code> <!-- Adds all files in the directory --></pre>
</li>
<li><strong>Commit Your Changes:</strong> Commit your staged changes with a message:
<pre><code>git commit -m "Describe your changes"</code></pre>
<pre><code>git commit -m "Add initial guide content"</code></pre>
</li>
<li><strong>Amend the Last Commit:</strong> Modify the most recent commit (e.g., change the commit message):
<pre><code>git commit --amend</code></pre>
<pre><code>git commit --amend -m "Updated commit message"</code></pre>
</li>
<li><strong>View Commit History:</strong> View a list of previous commits:
<pre><code>git log</code></pre>
For a simplified view:
<pre><code>git log --oneline</code></pre>
</li>
<li><strong>Create a New Branch:</strong> Create a new branch for new features or fixes:
<pre><code>git branch new-feature</code></pre>
<pre><code>git branch feature-xyz</code></pre>
</li>
<li><strong>Switch Between Branches:</strong> Move between branches:
<pre><code>git checkout branch-name</code></pre>
<pre><code>git checkout main</code></pre>
Alternatively:
<pre><code>git switch branch-name</code></pre>
<pre><code>git switch main</code></pre>
</li>
<li><strong>Merge Branches:</strong> Merge changes from a branch back into the main branch:
<pre><code>git merge branch-name</code></pre>
<pre><code>git merge feature-xyz</code></pre>
</li>
<li><strong>Push Changes to a Remote Repository:</strong> Push your changes to a remote repository (e.g., GitHub
or GitLab):
<pre><code>git push origin branch-name</code></pre>
<pre><code>git push origin main</code></pre>
For the first push or to set up tracking for a new branch:
<pre><code>git push -u origin branch-name</code></pre>
<pre><code>git push -u origin main</code></pre>
</li>
<li><strong>Pull Changes from Remote Repository:</strong> Update your local repository with changes from the
remote repository:
<pre><code>git pull</code></pre>
</li>
<li><strong>Undo Local Changes:</strong> Discard changes in the working directory:
<pre><code>git checkout -- filename</code></pre>
<pre><code>git checkout -- learn_git.html</code></pre>
</li>
<li><strong>Unstage Changes:</strong> Unstage a file without losing its changes:
<pre><code>git reset filename</code></pre>
<pre><code>git reset learn_git.html</code></pre>
</li>
<li><strong>Remove Files from Git:</strong> Stop tracking a file but keep it in your local directory:
<pre><code>git rm --cached filename</code></pre>
<pre><code>git rm --cached learn_git.html</code></pre>
</li>
<li><strong>Rebase Branches:</strong> Reapply changes on top of another branch:
<pre><code>git rebase branch-name</code></pre>
<pre><code>git rebase main</code></pre>
</li>
<li><strong>Stash Changes:</strong> Temporarily save your work and switch branches:
<pre><code>git stash</code></pre>
Retrieve stashed changes with:
<pre><code>git stash pop</code></pre>
</li>
<li><strong>View Differences:</strong> See changes between commits:
<pre><code>git diff</code></pre>
</li>
<li><strong>Keep Learning:</strong> Practice Git regularly and explore advanced features. Visit the <a
href="https://git-scm.com/doc" target="_blank">Git documentation</a> for more resources.
</li>
</ol>
<ul class="reference-note">
<p><strong>For reference:</strong></p>
<p>The naming convention is as under:</p>
<ul>
<li>User Name: Zahid</li>
<li>Email: [email protected]</li>
<li>Repository Name: learn_git</li>
<li>Branch Name: main</li>
<li>File Name: learn_git.html</li>
</ul>
</ul>
</body>
</html>