Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use git get and put instead of git pull and push

As explained on Don't Be Scared of git rebase, git fetch+rebase is a better alternative to git pull; unfortunately it's not as concise.

git get

From now on, use git get instead of git pull, a custom command that does this:

# get data from remote
git fetch origin
# rebase the remote branch with the same name as local
git rebase origin/$(git rev-parse --abbrev-ref HEAD) 

Set it up by running this command:

git config --global alias.get '!git fetch origin && git rebase origin/$(git rev-parse --abbrev-ref HEAD)'

git put

If you're ready to push, simply run git put. It will run the above + git push. To set it up, run this:

git config --global alias.put '!git fetch origin && git rebase origin/$(git rev-parse --abbrev-ref HEAD) && git push origin HEAD'

This comment has been minimized.

Copy link

commented Apr 11, 2018

Thank you so much. This saves me a lot of time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.