Git Command Reference Cheat Sheet
 Share
The version of the browser you are using is no longer supported. Please upgrade to a supported browser.Dismiss

 
View only
 
 
ABCDEFGHIJKLMNOPQRST
1
TaskCommand / Reference URLNotes
2
Getting started with Githttp://www.youtube.com/watch?v=ZDR433b0HJY
3
4
Further Reading
5
Line endings ^M issueshttp://stackoverflow.com/questions/1889559/git-diff-to-ignore-m
6
7
James' Shortlist of Commands
8
Start a new project in the current foldergit init
9
View your current branch and pending commitsgit status
10
Add the current tree of files to the next commitgit add .
11
Switch to your master branch snapshotgit checkout master
12
Switch to your branch bluegit checkout blue
13
Merge branch blue into your currnet branchgit merge blue
14
15
16
17
Installing & Configuring on Ubuntu
18
Install git on an ubuntu systemapt-get install git
19
Specify your name after git is installedgit config --global user.name "Jared De Blander"
20
Specify your email after git is installedgit config --global user.email jared0x90@gmail.com
21
Auto unix line endingsgit config --global core.autocrlf true
22
Enable colored outputgit config --global color.ui true
23
Cache password for some timegit config --global credential.helper cache
24
Location of your git config file~/.gitconfig
25
Shortcut to edit your global .gitconfiggit config --global -e
26
My basic ~/.gitconfighttps://github.com/jared0x90/dotfiles
27
28
Working with Git
29
Start a new project in the current foldergit init
30
View your current branch and pending commitsgit status
31
Add the current tree of files to the next commitgit add .Files matching those in .gitignore will not be included in the next commit. See the .gitignore section
32
Perform a diff compared to the prior snapshotgit diff
33
Perform a diff compared to the prior snapshot and use colorgit diff --colorYou can turn on colors by default in your ~/.gitconfig file
34
Show diff of yellow from common ancestor to the HEAD that will be mergedgit diff ...yellowNote the 3 dots
35
Show list of files from yellow to common ancestor to the HEAD that will be mergedgit diff --name-status ...yellowNote the 3 dots
36
Commit the currently added files with a commit messagegit commit -m 'your message'
37
Commit any modified files that are in the current snapshotgit commit -a -m 'your message'
38
Clear out the pending commit from git addsgit reset HEADIf this fails read the failure message and see what else you need to do. you may need to force a reset if it involved file deletion
39
Reset/revert ALL changes to a working copygit reset --hardThis will reset all changes in your working copy
40
Undo most recent commit on current branch.git reset --hard HEAD~1This will wipe out the prior version completely including history, modifications, etc
41
Remove a file from the repo on the next commitgit rm 'somefile.ext'
42
View the snapshot loggit log
43
Show commits in yellow that would be merged into current branch git log ..yellowNote the 2 dots.
44
Search your current branch for a case sensitive text pattern such as bluegit grep blue
45
Search your current branch for a case insensitive text pattern such as bLuEgit grep -i bLuE
46
View the list of your local branches and your current branchgit branch
47
View the list of all local and remote branches you havegit branch -a
48
View the list of all remote branchesgit branch -r
49
Create a new branch called blue from current snapshot and switch to itgit checkout -b blue
50
Create a new bracnh called yellow from current snapshot but don't switch to itgit branch yellowGenerally git checkout -b will be simpler as you typically want to switch to your new branch
51
Switch to your master branch snapshotgit checkout master
52
Switch to your branch bluegit checkout blue
53
Switch to a remote branch to previewgit checkout origin/somebranchYou shouldn't really make changes here. This puts you in detatched head state. More of a read-only view. Create your own local branch
54
Switch to a remote branch and then branch it for yourselfgit checkout origin/somebranch; git checkout -b your_new_branchThis is a 2 step process.
55
Merge branch blue into your currnet branchgit merge blue
56
Dealing with merge conflictshttp://www.youtube.com/watch?v=ZDR433b0HJY?t=52m50s
57
Delete a branch called yellowgit branch -d yellowLowercase -d is safe delete. Will not delete unique data. Uppercase -D is a forced delete
58
Delete a remote branched called yellowgit push origin --delete yellow
59
Delete a remote branched called yellow (shorthand)git push origin :yellowNotice the colon ( : ) before yellow
60
Remove your local copies of remote branches that are no longer in use from a remote named origingit remote prune origin
61
62
Working with Git Remotes
63
Adding a remote named origingit remote add origin https://some.thing.com/yourfiles-git.git
64
65
Managing the .gitignore file
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
Loading...
 
 
 
Sheet1