Skip to content

Instantly share code, notes, and snippets.

@fregante
Created June 30, 2015 18:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fregante/36e50e20e7927b052372 to your computer and use it in GitHub Desktop.
Save fregante/36e50e20e7927b052372 to your computer and use it in GitHub Desktop.
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'
@yakov116
Copy link

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