These are some things I find myself doing with git intermittently, but with such a low frequency that I haven't memorized them.
There are multiple ways to perform the actions outlined in this gist, but this is my preferred way of doing them 🤷♂️
# I want to work on a remote branch
git checkout master
git fetch
git checkout -b {local branch} origin/{branch} # Shorthand: git checkout -t <name of remote>/<name of branch>
# I want to include new stuff from master in my local branch
git checkout {local branch}
git fetch
git rebase origin/master
# I want to unf*ck the root commit on origin/master
git checkout --orphan {local branch} # Now change what you needs to be changed and commit the changes
git checkout master
git reset --hard {local branch} # Overwrite master with unfucked master branch
git push origin master -f # Force the push to origin
git branch -D {local branch} # Clean up the orphan branch
# I need to apply a specific commit from a different branch to the head of whatever branch I am on
git cherry-pick {SHA-1} --no-commit
# I want to add a mirror remote to my repository
git remote add mirror git@bitbucket.org:YOUR_USERNAME/your_project.git # Bitbucket
git remote add mirror git@github.com:YOUR_USERNAME/your_project.git # Github
git remote add mirror git@gitlab.com:YOUR_USERNAME/your_project.git # GitLab
git remote -v # To verify origin and mirror