Git and Teamwork, Advanced
Cheat sheet · Level 1
Undo, tidy and merge as a team
Every command and idea of this level on one page: what to type, what it does, and what you see.
1Undo a change you didn't save
restore.
What to type What it does You see git restore index.htmlPut index.html back nothing to commit, working tree clean 2Stage every change at once
add with a dot.
What to type What it does You see git add .Stage everything with a dot · git commit -m "Add hours"Commit with the note Add hours 2 files changed, 2 insertions(+) 3Take a file off the stage
restore --staged.
What to type What it does You see git restore --staged notes.txtTake notes.txt off the stage · git commit -m "Add menu line"Commit with the note Add menu line Untracked files: 4See exactly what you will save
diff --staged.
What to type What it does You see git diff --stagedRead the stage · git commit -m "New coffee price"Commit with the note New coffee price +<p>Coffee 3 dollars</p> 5Stage and save in one step
commit -am.
What to type What it does You see git commit -am "Fix price"Save the price with -am · git commit -m "Add drinks"Commit with the note Add drinks 1 file changed, 1 insertion(+) 6Only the newest save points
log -3 and log -1.
What to type What it does You see git log --oneline -3Show only the last three · git log -1Show the newest in full Add allergy info 7Peek at a teammate's branch
log <branch>.
What to type What it does You see git log --oneline bookingRead the booking branch a66a8f4 (booking) Add booking form 8Make a branch, stay where you are
branch <name>.
What to type What it does You see git branch menuMake the branch menu * main menu 9Twist: save before you switch
Git protects unsaved work.
What to type What it does You see git commit -am "Add phone number"Save with the note Add phone number Switched to branch 'booking' 10When both sides moved
A merge commit.
What to type What it does You see git merge bookingMerge booking · git log --onelineShow the history Merge made by the 'ort' strategy. 11Tidy up a finished branch
branch -d.
What to type What it does You see git branch -d bookingDelete the booking branch Deleted branch booking (was 0e79770). 12Back out of a merge
merge --abort.
What to type What it does You see git merge titleMerge title · git merge --abortCancel the merge CONFLICT (content): Merge conflict in index.html 13Keep both sides
A conflict where both are right.
What to type What it does You see git merge saladMerge salad · git commit -m "Merge salad"Commit with the note Merge salad CONFLICT (content): Merge conflict in menu.html 14On your own: the new prices
Undo, merge, tidy, with no gold line.
What to type What it does You see git restore index.htmlThrow the junk away · git branch -d pricesDelete the prices branch Merge made by the 'ort' strategy.