└── README.md
/README.md:
--------------------------------------------------------------------------------
1 | # Git Cheat Sheet
2 | My go-to cheat sheet for Git commands! Photo created by REBELLABS by ZEROTURNAROUND.
3 |
4 | ## 📸 Photo Version
5 |
6 | 
7 |
8 | ## 💭 Text Version
9 |
10 | ### 🛠 Create a Repository
11 |
12 | From scratch -- Create a new local repository
13 |
14 | ```git init [project name]```
15 |
16 | Download from an existing repository
17 |
18 | ```git clone my_url```
19 |
20 | ### 🔎 Observe your Repository
21 | List new or modified files not yet committed
22 |
23 | ```git status```
24 |
25 | Show the changes to files not yet staged
26 |
27 | ```git diff```
28 |
29 | Show the changes to staged files
30 |
31 | ```git diff --cached```
32 |
33 | Show all staged and unstaged file changes
34 |
35 | ```git diff HEAD```
36 |
37 | Show the changes between two commit ids
38 |
39 | ```git diff commit1 commit2```
40 |
41 | List the change dates and authors for a file
42 |
43 | ```git blame [file]```
44 |
45 | Show the file changes for a commit id and/or file
46 |
47 | ```git show [commit]: [file]```
48 |
49 | Show full change history
50 |
51 | ```git log```
52 |
53 | Show change history for file/directory including diffs
54 |
55 | ```git log -p [file/directory]```
56 |
57 | ### 🌴 Working with Branches
58 | List all local branches
59 |
60 | ```git branch```
61 |
62 | List all oranches, local and remote
63 |
64 | ```git branch```
65 |
66 | Switch to a branch, my _branch, and update working directory
67 |
68 | ```git checkout my_branch```
69 |
70 | Create a new branch called new branch
71 |
72 | ```git branch new_branch```
73 |
74 | Delete the branch called my_branch
75 |
76 | ```git branch -d my_branch```
77 |
78 | Merge branch _a into branch_b
79 |
80 | ```git checkout branch_b```
81 | ```git merge branch_a```
82 |
83 | Tag the current commit
84 |
85 | ```git tag my_tag```
86 |
87 | ### 👛 Make a change
88 | Stages the file, ready for commit
89 |
90 | ```git add [file]```
91 |
92 | Stage all changed files, ready for commit
93 |
94 | ```git add .```
95 |
96 | Commit all staged files to versioned history
97 |
98 | ```git commit -m "commit message"```
99 |
100 | Commit all your tracked files to versioned history
101 |
102 | ```git commit -am "commit message```
103 |
104 | Unstages file, keeping the file changes
105 |
106 | ```git reset [file]```
107 |
108 | Revert everything to the last commit
109 |
110 | ```git reset --hard```
111 |
112 | Overwrite commit history with your own local history (force push):
113 | ```git push --force```
114 |
115 | ### 🚰 Synchronize
116 | Get the latest changes from origin (no merge)
117 |
118 | ```git fetch```
119 |
120 | Fetch the latest changes from origin and merge
121 |
122 | ```git pull```
123 |
124 | Fetch the latest changes from origin and rebase
125 |
126 | ```git pull --rebase```
127 |
128 | Push local changes to the origin
129 |
130 | ```git push```
131 |
132 | ### 🎬 Finally!
133 | When in doubt, use git help
134 |
135 | ```git command --help```
136 |
137 | Or visit https://training.github.com/ for official GitHub training.
138 |
--------------------------------------------------------------------------------