git sync
For https://github.com-based projects, I most often just fetch upstream/master
and branch from FETCH_HEAD
to create topic branches, but occasionally I like to keep my local and origin/master
branches up to date:
git pull -p --ff-only upstream master
git push # assumes local master is tracking origin/master
git fetch -p
In bash and https://github.com/powershell/powershell 7 I can do this in a single line separating commands with &&
, but it’s a lot to type over and over. Shells’ history only lasts so long. Instead, I was able to combine this into a command alias in ~/.gitconfig:
git config --global alias.sync "!git pull -p --ff-only upstream master && git push origin master && git fetch -p origin"
Now, I can just run the following:
git sync
Edits
- 2020-07-30: updated command line to be more explicit. See gist for latest.
Tags: git