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.

Take the level exam
  1. 1Undo a change you didn't save

    restore.

    What to typeWhat it doesYou see
    git restore index.htmlPut index.html backnothing to commit, working tree clean
  2. 2Stage every change at once

    add with a dot.

    What to typeWhat it doesYou see
    git add .Stage everything with a dot·
    git commit -m "Add hours"Commit with the note Add hours2 files changed, 2 insertions(+)
  3. 3Take a file off the stage

    restore --staged.

    What to typeWhat it doesYou see
    git restore --staged notes.txtTake notes.txt off the stage·
    git commit -m "Add menu line"Commit with the note Add menu lineUntracked files:
  4. 4See exactly what you will save

    diff --staged.

    What to typeWhat it doesYou see
    git diff --stagedRead the stage·
    git commit -m "New coffee price"Commit with the note New coffee price+<p>Coffee 3 dollars</p>
  5. 5Stage and save in one step

    commit -am.

    What to typeWhat it doesYou see
    git commit -am "Fix price"Save the price with -am·
    git commit -m "Add drinks"Commit with the note Add drinks1 file changed, 1 insertion(+)
  6. 6Only the newest save points

    log -3 and log -1.

    What to typeWhat it doesYou see
    git log --oneline -3Show only the last three·
    git log -1Show the newest in fullAdd allergy info
  7. 7Peek at a teammate's branch

    log <branch>.

    What to typeWhat it doesYou see
    git log --oneline bookingRead the booking brancha66a8f4 (booking) Add booking form
  8. 8Make a branch, stay where you are

    branch <name>.

    What to typeWhat it doesYou see
    git branch menuMake the branch menu* main menu
  9. 9Twist: save before you switch

    Git protects unsaved work.

    What to typeWhat it doesYou see
    git commit -am "Add phone number"Save with the note Add phone numberSwitched to branch 'booking'
  10. 10When both sides moved

    A merge commit.

    What to typeWhat it doesYou see
    git merge bookingMerge booking·
    git log --onelineShow the historyMerge made by the 'ort' strategy.
  11. 11Tidy up a finished branch

    branch -d.

    What to typeWhat it doesYou see
    git branch -d bookingDelete the booking branchDeleted branch booking (was 0e79770).
  12. 12Back out of a merge

    merge --abort.

    What to typeWhat it doesYou see
    git merge titleMerge title·
    git merge --abortCancel the mergeCONFLICT (content): Merge conflict in index.html
  13. 13Keep both sides

    A conflict where both are right.

    What to typeWhat it doesYou see
    git merge saladMerge salad·
    git commit -m "Merge salad"Commit with the note Merge saladCONFLICT (content): Merge conflict in menu.html
  14. 14On your own: the new prices

    Undo, merge, tidy, with no gold line.

    What to typeWhat it doesYou see
    git restore index.htmlThrow the junk away·
    git branch -d pricesDelete the prices branchMerge made by the 'ort' strategy.