Ben's notes

Git Commands (reference)

Note: See previous post

git fetch
git pull
git push
git cherry-pick <commit>

git rebase [dest-branch]
git merge [dest-branch]

rebase or merge current branch or commit (the one head is pointing to) with [dest-branch]


git status
  • Will, among other things, show the status of a merge in progress.
  • During a merge, short Format “-s” is a useful option, will show (for each path):
    • A completed merge or no merge: X: Index, Y: Working directory
    • A merge in progress: XY are changes introduced by each merge candidate (note: unmodified files, aka “paths”, are not listed)

git revert <commit>

Unlike reset will create a new commit where the everything is the same except for the specified commit (i.e. doesn’t include history)

git restore .

Restores unstaged files in the working directory from the index.


git reset --option <target>
  • From the manual, reset —hard usually goes through three steps:
    1. Move the HEAD and the branch HEAD points to to another reference.
      • reset --soft (as —option stops at this point)
    2. Make the index look like HEAD.
      • reset --mixed (as —option stops at this point)
    3. Make the working directory look like the index.
      • reset --hard (as —option)
  • Like git checkout except it moves the HEAD as well as the current branch pointer—leaving the node(s) orphaned
  • “git reset” defaults to “git reset —mixed HEAD”
  • Will reset back to specified commit (or where HEAD is pointed to), removing commits inbetween as well.
git rev-parse --show-toplevel

From this stackoverflow post. Will show the location of the git repo when in a subdirectory.