Git Shit Done

the rest of the cheatsheet can be found here. Forked from Scott Spence :).

Learn Git

delete branch

delete branch locally

git branch -d localBranchName

delete branch remotely

git push origin --delete remoteBranchName

source

Add files to last commit

# make your change
git add . # or add individual files
git commit --amend --no-edit
# now your last commit contains that change!
# WARNING: never amend public commits

src

Undo last commit (on local & remote)

git reset --hard HEAD^
git push -f

HEAD^ means one revision back (this is the local step) then you force push to origin. without the force flag, you’ll get an error from git - telling you about the one incoming change from remote, which you’re trying to remove:) src

Create a local branch and push it to GitHub

Want to make your feature branch and get it on GitHub?

Make your branch first then:

git push --set-upstream origin <branch-you-just-created>

Quickly checkout to previous branch

git checkout -

Housekeeping - prune branches that don’t exist on origin

git fetch --prune

Get Origin URL

  • I was in a feature branch, and needed to do PR things, but was too lazy to go through GitHub UI to try and figure out where the repo is. Figured commandline would be a lot quicker to find my way around, and it was :)
git config --get remote.origin.url

Interactive Rebase

git rebase -i HEAD~3

Git Under The Hood

  • structure of the .git folder - the important files and the role they play
  • the different types of git objects