Skip to content

Instantly share code, notes, and snippets.

@a7madgamal
Forked from arnauldvm/.gitconfig
Created December 17, 2018 15:52
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 a7madgamal/f581763eaff88dd1d4ddc044cd4e6807 to your computer and use it in GitHub Desktop.
Save a7madgamal/f581763eaff88dd1d4ddc044cd4e6807 to your computer and use it in GitHub Desktop.
Git sync all local tracking branches with remotes
[alias]
tracking = "!f() { git for-each-ref --format '%(refname:short):%(upstream:short)' 'refs/heads' | grep -Ev ':$'; }; f"
is-clean-workdir = "!f() { git diff --stat --exit-code || { echo \"Workdir dirty\"; exit 1; }; }; f"
is-clean-index = "!f() { git diff --stat --cached --exit-code || { echo \"Index dirty\"; exit 2; }; }; f"
is-clean = "!f() { git is-clean-workdir && git is-clean-index; }; f"
co-merge = "!f() { local=\"$1\"; remote=\"$2\"; git checkout \"$local\"; git merge --ff-only \"$remote\"; }; f"
current-branch = rev-parse --abbrev-ref HEAD
sync = "!f() { git stash push -u -m AUTO_STASH && git is-clean || { echo Aborting sync.; exit 1; }; current=$(git current-branch); git fetch --all; git tracking | while IFS=: read local remote; do echo \"Merging $local with $remote\"; git co-merge \"$local\" \"$remote\"; done 3>&1 1>&2 2>&3 | grep -iE --color 'fatal|$' 3>&1 1>&2 2>&3; git checkout \"$current\"; git stash pop; }; f"
@mv5903
Copy link

mv5903 commented May 13, 2022

nice work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment