-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheat-sheet.html
More file actions
247 lines (147 loc) · 10.7 KB
/
Copy pathcheat-sheet.html
File metadata and controls
247 lines (147 loc) · 10.7 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<link href="/feed.xml" type="application/atom+xml" rel="alternate" title="GitHub Cheatsheets Feed">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
<link rel="stylesheet" href="assets/main.css">
<!-- begin SEO -->
<title>GitHub Git Cheat Sheet - GitHub Cheatsheets</title>
<meta property="description" content="Github Git Cheat Sheets Training Kit">
<meta property="og:locale" content="en-US">
<meta property="og:site_name" content="GitHub Cheatsheets">
<meta property="og:title" content="GitHub Git Cheat Sheet">
<link rel="canonical" href="https://training.github.com/downloads/github-git-cheat-sheet/">
<meta property="og:url" content="https://training.github.com/downloads/github-git-cheat-sheet/">
<!-- end SEO -->
</head>
<body style="min-height: 100vh;" class="d-flex flex-column">
<div class="bg-red py-3 f5 flex-none text-white">
<header class="container-lg p-responsive site-header js-site-header d-block clearfix">
<a class="no-underline text-inherit text-bold d-flex flex-items-center lh-condensed-ultra float-left" href="/">
<div class="mr-3"><svg class="octicon octicon-mark-github" viewbox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg></div>
</a>
<button class="btn-link float-right site-header-toggle js-site-header-toggle" type="button" aria-label="Toggle navigation" aria-expanded="false">
<svg class="octicon octicon-three-bars" viewbox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11.41 9H.59C0 9 0 8.59 0 8c0-.59 0-1 .59-1H11.4c.59 0 .59.41.59 1 0 .59 0 1-.59 1h.01zm0-4H.59C0 5 0 4.59 0 4c0-.59 0-1 .59-1H11.4c.59 0 .59.41.59 1 0 .59 0 1-.59 1h.01zM.59 11H11.4c.59 0 .59.41.59 1 0 .59 0 1-.59 1H.59C0 13 0 12.59 0 12c0-.59 0-1 .59-1z"></path></svg>
</button>
<nav class="site-header-menu float-none float-md-right py-1 mt-4 mt-md-0">
<ul class="d-block d-md-flex list-style-none">
</ul>
</nav>
</header>
</div>
<main class="site-content">
<div class="container-lg p-responsive">
<div class="markdown-body d-flex flex-wrap gutter">
<div class="col-md-6">
<h2 id="install">Install</h2>
<h3 id="github-desktop">GitHub Desktop</h3>
<p><a href="https://desktop.github.com">desktop.github.com</a></p>
<h3 id="git-for-all-platforms">Git for All Platforms</h3>
<p><a href="https://git-scm.com">git-scm.com</a></p>
<h2 id="configure-tooling">Configure tooling</h2>
<p>Configure user information for all local repositories</p>
<p><code class="language-plaintext highlighter-rouge">$ git config --global user.name "[name]"</code></p>
<p>Sets the name you want attached to your commit transactions</p>
<p><code class="language-plaintext highlighter-rouge">$ git config --global user.email "[email address]"</code></p>
<p>Sets the email you want attached to your commit transactions</p>
<p><code class="language-plaintext highlighter-rouge">$ git config --global color.ui auto</code></p>
<p>Enables helpful colorization of command line output</p>
<h2 id="branches">Branches</h2>
<p>Branches are an important part of working with Git. Any commits you make will be made on the branch you’re currently “checked out” to. Use <code class="language-plaintext highlighter-rouge">git status</code> to see which branch that is.</p>
<p><code class="language-plaintext highlighter-rouge">$ git branch [branch-name]</code></p>
<p>Creates a new branch</p>
<p><code class="language-plaintext highlighter-rouge">$ git checkout [branch-name]</code></p>
<p>Switches to the specified branch and updates the working directory</p>
<p><code class="language-plaintext highlighter-rouge">$ git merge [branch]</code></p>
<p>Combines the specified branch’s history into the current branch. This is usually done in pull requests, but is an important Git operation.</p>
<p><code class="language-plaintext highlighter-rouge">$ git branch -d [branch-name]</code></p>
<p>Deletes the specified branch</p>
</div>
<div class="col-md-6">
<h2 id="create-repositories">Create repositories</h2>
<p>A new repository can either be created locally, or an existing repository can be cloned. When a repository was initialized locally, you have to push it to GitHub afterwards.</p>
<p><code class="language-plaintext highlighter-rouge">$ git init</code></p>
<p>The git init command turns an existing directory into a new Git repository inside the folder you are running this command. After using the <code class="language-plaintext highlighter-rouge">git init</code> command, link the local repository to an empty GitHub repository using the following command:</p>
<p><code class="language-plaintext highlighter-rouge">$ git remote add origin [url]</code></p>
<p>Specifies the remote repository for your local repository. The url points to a repository on GitHub.</p>
<p><code class="language-plaintext highlighter-rouge">$ git clone [url]</code></p>
<p>Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits</p>
<h2 id="the-gitignore-file">The .gitignore file</h2>
<p>Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named <code class="language-plaintext highlighter-rouge">.gitignore</code>. You can find helpful templates for <code class="language-plaintext highlighter-rouge">.gitignore</code> files at <a href="https://github.com/github/gitignore">github.com/github/gitignore</a>.</p>
<h2 id="synchronize-changes">Synchronize changes</h2>
<p>Synchronize your local repository with the remote repository on GitHub.com</p>
<p><code class="language-plaintext highlighter-rouge">$ git fetch</code></p>
<p>Downloads all history from the remote tracking branches</p>
<p><code class="language-plaintext highlighter-rouge">$ git merge</code></p>
<p>Combines remote tracking branches into current local branch</p>
<p><code class="language-plaintext highlighter-rouge">$ git push</code></p>
<p>Uploads all local branch commits to GitHub</p>
<p><code class="language-plaintext highlighter-rouge">$ git pull</code></p>
<p>Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. <code class="language-plaintext highlighter-rouge">git pull</code> is a combination of <code class="language-plaintext highlighter-rouge">git fetch</code> and <code class="language-plaintext highlighter-rouge">git merge</code></p>
</div>
<div class="clearfix"></div>
<div class="col-md-6">
<h2 id="make-changes">Make changes</h2>
<p>Browse and inspect the evolution of project files</p>
<p><code class="language-plaintext highlighter-rouge">$ git log</code></p>
<p>Lists version history for the current branch</p>
<p><code class="language-plaintext highlighter-rouge">$ git log --follow [file]</code></p>
<p>Lists version history for a file, beyond renames (works only for a single file)</p>
<p><code class="language-plaintext highlighter-rouge">$ git diff [first-branch]...[second-branch]</code></p>
<p>Shows content differences between two branches</p>
<p><code class="language-plaintext highlighter-rouge">$ git show [commit]</code></p>
<p>Outputs metadata and content changes of the specified commit</p>
<p><code class="language-plaintext highlighter-rouge">$ git add [file]</code></p>
<p>Snapshots the file in preparation for versioning</p>
<p><code class="language-plaintext highlighter-rouge">$ git commit -m "[descriptive message]"</code></p>
<p>Records file snapshots permanently in version history</p>
<h2 id="redo-commits">Redo commits</h2>
<p>Erase mistakes and craft replacement history</p>
<p><code class="language-plaintext highlighter-rouge">$ git reset [commit]</code></p>
<p>Undoes all commits after <code class="language-plaintext highlighter-rouge">[commit]</code>, preserving changes locally</p>
<p><code class="language-plaintext highlighter-rouge">$ git reset --hard [commit]</code></p>
<p>Discards all history and changes back to the specified commit</p>
<blockquote>
<p>CAUTION! Changing history can have nasty side effects. If you need to change commits that exist on GitHub (the remote), proceed with caution. If you need help, reach out at <a href="https://github.community">github.community</a> or contact support.</p>
</blockquote>
</div>
<div class="col-md-6">
<h2 id="glossary">Glossary</h2>
<ul>
<li>
<strong>git</strong>: an open source, distributed version-control system</li>
<li>
<strong>GitHub</strong>: a platform for hosting and collaborating on Git repositories</li>
<li>
<strong>commit</strong>: a Git object, a snapshot of your entire repository compressed into a SHA</li>
<li>
<strong>branch</strong>: a lightweight movable pointer to a commit</li>
<li>
<strong>clone</strong>: a local version of a repository, including all commits and branches</li>
<li>
<strong>remote</strong>: a common repository on GitHub that all team members use to exchange their changes</li>
<li>
<strong>fork</strong>: a copy of a repository on GitHub owned by a different user</li>
<li>
<strong>pull request</strong>: a place to compare and discuss the differences introduced on a branch with reviews, comments, integrated tests, and more</li>
<li>
<strong>HEAD</strong>: representing your current working directory, the HEAD pointer can be moved to different branches, tags, or commits when using <code class="language-plaintext highlighter-rouge">git checkout</code>
</li>
</ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</main>
<footer class="bg-gray-light border-top py-4 text-gray text-center mt-6 flex-none">
<span aria-label="Made with love by GitHub and friends">
Made with <img class="emoji" title=":heart:" alt=":heart:" src="https://github.githubassets.com/images/icons/emoji/unicode/2764.png" height="20" width="20"> by <img class="emoji" title=":octocat:" alt=":octocat:" src="https://github.githubassets.com/images/icons/emoji/octocat.png" height="20" width="20">s and friends
</a>
</span>
<p>© 2021 OSC, CU.
</p>
</footer>
</body>
</html>