Skip to content

Instantly share code, notes, and snippets.

@glennfu
Created October 30, 2015 17:42
Show Gist options
  • Save glennfu/41153b9800d1a5d4e5a3 to your computer and use it in GitHub Desktop.
Save glennfu/41153b9800d1a5d4e5a3 to your computer and use it in GitHub Desktop.
My Git Cheatsheet

Create a remote branch

git pull git push origin master:refs/heads/new_branch git co -b new_branch --track origin/new_branch

Create a remote branch from your current branch

git push origin localbranch:remotebranch

Delete a remote branch

git push origin :remote_branch_name

Pushing to a differently named remote branch

git push

Show commits that are in branch1 and not in branch2

git log branch1 ^branch2

Squashing commits

git rebase -i SHA_OF_FIRST_PRIOR_UNRELATED_COMMIT replace 'pick' with 's' for all except the top (earliest) commit delete all commit messages and replace with just 1 message

Find where something went in a file

git log -S"text I'm looking for" /path/to/file.name

Find where something went in stash

for i in git reflog --pretty=format:%H stash; do git grep “text I’m looking for” $i; done

Find where something went in all files

git log -S”text I’m looking for”

Squash via rebuilding branch from a diff file

git diff SHA_OF_FIRST_PRIOR_UNRELATED_COMMIT > ~/patchfile git co SHA_OF_FIRST_PRIOR_UNRELATED_COMMIT git co new_branch_name patch -p1 < ~/patchfile

Dealing with forked repos

https://help.github.com/articles/fork-a-repo

Create pull request from commit

git co -b upstream upstream/master git cherry-pick SHA git push origin upstream

  • create pull request from that branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment