Skip to content

Instantly share code, notes, and snippets.

@wgao19
Last active June 28, 2022 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wgao19/cb54200800aa05164f57d398f151968c to your computer and use it in GitHub Desktop.
Save wgao19/cb54200800aa05164f57d398f151968c to your computer and use it in GitHub Desktop.
Git cheatsheet

upstream to main repo

$ git remote add upstream git@github.com:main-repo.git
$ git fetch upstream
$ git branch --set-upstream-to=upstream/master master

set remot url

$ git remote set-url origin ???url

remove local branches that are already merged

StackOverflow link

  • git remote prune origin prunes tracking branches not on the remote
  • git branch --merged lists branches that have been merged into the current branch.
  • xargs git branch -d deletes branches listed on standard input.
  • Be careful deleting branches listed by git branch --merged. The list could include master or other branches you'd prefer not to delete.

To give yourself the opportunity to edit the list before deleting branches, you could do the following in one line:

git branch --merged >/tmp/merged-branches && vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches

glol

alias glol="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment