/git-cheatsheet

My personal git reference (with a nifty CLI viewer)

Primary LanguagePython

Git Cheatsheet

Just my own git commands reference for personal use.

Install the CLI tool (with or without Python) here. Seriously, do it! It's super useful. Supports Windows!

Branch stuff

Change file in multiple branches

git log  # get commit SHA [make sure it's the right one]
git checkout <branch>
git cherry-pick COMMIT_SHA

Source

Compare file in multiple branches

git diff <b> <b> -- myfile.pog

Source

Delete local branch

git branch -D <branch>

Update deletion of local branch on remote

git push <remote-name> :<branch>

Rename branch

# local branch
git branch -m <new-name>
# other branch
git branch -m <old-nane> <new-name>

# to update/delete on remote
git push <remote-name> :<old-name>
# delete the old upstream as it hasn't been updated with new name
git branch --unset-upstream <new-name>
# push renamed branch to remote
git push <remote-name> <new-name>
# set the correct upstream for the newly pushed local branch
git push <remote-name> -u <new_name>
# response will look something like this
# "Branch 'new_branch_name' set up to track remote branch 'new_branch_name' from 'origin'."

Source

Checkout branch on remote locally

git pull
# you should see something like this:
" * [test branch]      test_branch -> origin/test_branch"
git checkout <branch-name>

Remove branch that was deleted on remote

# ensure you are not checked out on the branch you wish to delete
git branch --merged >/tmp/merged-branches && \
  vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches
# select the ones to delete with an astericks, press your I key to insert. Escape key when you're done. `:wq` to finish!

Source

Terminology

Origin/<remote-name>

In Git, "origin" is a shorthand name for the remote repository that a project was originally cloned from.
More precisely, it is used instead of that original repository's URL - and thereby makes referencing much easier.
Note that origin is by no means a "magical" name, but just a standard convention.

Source