Git Cheat-sheet

From Georgia Tech Course Software Development (https://www.youtube.com/watch?v=3a2x1iJFJWc)
  • is a limited version of or

1. Log

2. Change history in one branch:

(1) add new file without creating new commit:

(2) modify comment:

(3) get rid of untracked files:

(d for directory, f for force)

(4) unstage:

has 2 types: , ,

(5) revert:

undo the effect of past commits by creating a new commit. This can keep the history intact and avoid conflict when other people already pulled your repo.

(6) delete a commit:

(7)reorder commits

(8) fixup/squash commits

(9) split a commit

3. Change history between branches

  • move commit from branch1 to branch2:

(copy the commit hash, e.g af1234)

4. clean history after merge

5. resolve 3-way/recursive merge conflict

rule 1: changed lines overwrites the unchanged

rule 2: deleted and changed are conflicting

6. command shortcut

= +

= +

= +

7. get out of a detached HEAD

( detached HEAD means pointing to a commit directly without branch)

(detached HEAD)

Option 1: checking out an existing branch

option 2: checking out a new branch

(HEAD, tmp_branch)

(HEAD -> tmp_branch)

8. stash

e.g.: when you want to checkout without a clean working area and don’t want to commit

9. sync with upstream

10. clean request after pull request

(branch feature-1 has no remote tracking because it is not on GitHub yet)

11. change history

In one branch:

add new file without creating new commit:

modify comment:

get rid of untracked files:

(d for directory, f for file)

Between branches, move commit from branch1 to branch2:

(copy the commit hash, e.g af1234)

12. Compare two branches

I am a Machine Learning Engineer with special interest in mental health and finance.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store