Last Updated: February 25, 2016
·
2.432K
· Gabriel Falcão

git push to do pull + push consecutively

At Yipit we have developers pushing to the dev branch in a per-minute basis.
Therefore we always have to run git pull and then git push to send our local commits.

Many people like using bash aliases like pp="git pull && git push" but I personally like using regular command than creating aliases.

Here is a solution for politely turning the "git sync" command into a combo of git pull + git push:

in your ~/.gitconfig:

[alias]
sync = !git-pull && git-push

[push]
default = current

the default = current under the push section guarantees that you will not fetch all the remote branches and push all of them, avoiding pushing local commits of other branches than the current one.

Simple, and effective. Use with awareness :)

Also, if you don't want to make this behavior global, you can rather add to the .git/config of specific git repositories

2 Responses
Add your response

Are you sure this works? It doesn't for me and the git-config man page says: "To avoid confusion and troubles with script usage, aliases that hide existing git commands are ignored."

over 1 year ago ·

Indeed! Thank you Brian, I updated the tip

over 1 year ago ·