Skip to content

Instantly share code, notes, and snippets.

@jirilebl
Last active March 7, 2021 23:38
Show Gist options
  • Save jirilebl/52192f024457bc1e2d4b40751c001270 to your computer and use it in GitHub Desktop.
Save jirilebl/52192f024457bc1e2d4b40751c001270 to your computer and use it in GitHub Desktop.
git commands I keep forgetting
remotes: origin = github, upstream = the thing we forked things from
# sync upstream master, make sure you're on master and push back out onto github (origin)
git fetch --all
git merge upstream/master
git push
# get branch from github and make a local tracking branch
git checkout -b dev origin/dev
# push local branch to github
git push -u origin branch
# view and add remotes
git remote -v
git remote add upstream https://github.com/foo/foo.git
# delete old branch where changes were already merged
# you should do pull -p afterwards to prune all old
# remote tracking branches
git branch -d old-branch
# store the credentials used to log in
git config credential.helper store
# whack local changes
git checkout -- .
# pull onto a dirty working tree just like cvs update did,
# only do the pop if git stash actually stashed something,
# otherwise it might pop a different stash
git stash
git pull
git stash pop
# cherry pick a specific commit onto the current branch
git cherry-pick 012345
# show all commits from branch which was branched from master
# and whether they were already cherry picked (- means already
# picked). Useful if thebranch is old stable and gets fixes
# that may need to be cherry picked onto master. The -v shows
# also the first line of the commit message
git cherry -v master thebranch
# pull and at the same time prune old tracking branches
# useful to do after the actual branches are deleted
# and if we forgot to delete the remote tracking branch
# at the same time
git pull -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment