Skip to content

Instantly share code, notes, and snippets.

@eloots
Last active July 4, 2019 14:55
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 eloots/e5887e64d00e76e084bea601bf4f638a to your computer and use it in GitHub Desktop.
Save eloots/e5887e64d00e76e084bea601bf4f638a to your computer and use it in GitHub Desktop.

Fetch remote branches and delete local branches that are not on remote

git remote update origin --prune

Fetching all remote tags from repository upstream

git fetch upstream 'refs/tags/*:refs/tags/*'

Delete a remote branch

git push origin --delete <branch_name>
git branch -d <branch_name>

Solving problem of git requesting passphrase on every single command (MacOSX Sierra specific...)

http://superuser.com/questions/1127067/macos-keeps-asking-my-ssh-passphrase-since-i-updated-to-sierra

Add the following to your ~/.ssh/config

Host *
    UseKeychain yes

Changing Author on a commit

git commit --amend --author="Author Name <email@address.com>"

Finding out which commits changed a particular file or a number of lines in a file

Find which commits changed a given file:

git log --follow exercise_000_initial_state/src/test/resources/README.md

Find which commits changes line 27..29 in file exercise_000_initial_state/src/test/resources/README.md:

git blame -L27,+2 -- exercise_000_initial_state/src/test/resources/README.md

Find which commit changed a particular segment of text in a file:

git log -S'Use the `nextExercise` command' -- exercise_000_initial_state/src/test/resources/README.md

Fetch a remote branch

Imagine we want to pull a branch called some-important-stuff on a remote named upstream. We do this as follows:

git fetch upstream some-important-stuff:some-important-stuff
git checkout some-important-stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment