My Git Cheetsheet

The whole point of this is so that I can document some of the tips, tricks, and gotchas I continually run into when submitting PRs so that I may not have to run into them again.

Creating and Maintaining a Fork

If working on an existing project, like say the kubernetes website, create a fork, and clone the fork. Remote add the upstream so you can constantly sync your fork to the upstream fairly easily from the cli

git clone
git remote add upstream
git remote -v

In order to sync your fork with the upstream:

git fetch upstream
git pull upstream master

---- Dont do this
git checkout master
git merge upstream/master

Tips and Tricks

Always sync your fork with the upstream

Create a new branch to work from for each issue so you keep the commits seperated. This makes it easy to fix later.

Rebase interactively to fix any of the commits youve submitted

git rebase -i HEAD~3

This will allow you to perform a rebase on the last 3 commits

The reflog has pretty much every action you’ve performed inside git. If you need to reset something, you can run reflog and reset your changes

git reflog

492f6eb6c [email protected]{14}: rebase -i (start): checkout HEAD~4
17c36d12b [email protected]{15}: pull: Merge made by the 'recursive' strategy.
b23199b6c [email protected]{16}: commit (amend): CentOS Repo for 1.15
327a101db [email protected]{17}: rebase -i (finish): returning to refs/heads/patch-3
327a101db [email protected]{18}: rebase -i: fast-forward

git reset (--hard) [email protected]{15}

For everything else: Oh Shit Git