The Ultimate All-in-One Git Bash Command
Sync, Merge, Push, Auto-Resolve Conflicts, Open PRs—One-Liner for Power Users
Tired of juggling Git commands?
Meet the ultimate all-in-one Bash workflow: a single command that automatically fetches, syncs, commits, merges, pushes, cleans, optimizes, auto-resolves merge conflicts, and even creates Pull Requests—for every branch in your repo.
Copy-paste this one-liner and level up your Git game:
git fetch --all && for branch in $(git branch | sed 's/[* ]//g'); do \
git checkout $branch && \
git pull origin $branch --no-rebase --allow-unrelated-histories || \
(git ls-files -u | cut -f2 | sort -u | xargs -I{} git checkout --ours {} && git add . && git commit -am "Auto-resolve conflicts with ours in $branch" || true); \
git add . && git commit -am "Update $branch" || true && git push origin $branch; \
done && \
git checkout main && \
for branch in $(git branch | grep -v main | sed 's/[* ]//g'); do \
git merge $branch --no-ff -m "Merge $branch into main" || \
(git ls-files -u | cut -f2 | sort -u | xargs -I{} git checkout --ours {} && git add . && git commit -am "Auto-resolve conflicts with ours during merge from $branch" || true); \
done && \
git push origin main && git fetch --prune && git gc && git clean -fdx && \
for branch in $(git branch | grep -v main | sed 's/[* ]//g'); do \
gh pr create --base main --head $branch --title "PR: Merge $branch" --body "Automated PR" || true; \
done
What does this do?
-
Fetches and updates all branches
-
Stages, commits, and pushes all changes (for every branch)
-
Attempts to auto-resolve merge conflicts using your local code (you can easily swap for remote)
-
Merges all feature branches into
main
-
Pushes the merged
main
branch -
Cleans, prunes, and garbage-collects your repo
-
Optionally creates Pull Requests (if you have GitHub CLI installed)
Why use this?
-
Save time: No more manual branch-hopping and repetitive commands
-
Reduce errors: Never forget a commit, push, or merge again
-
Works for any repo: Just paste and go!
-
Great for solo devs, teams, and power users
-
Auto-handles merge conflicts (configurable for “ours” or “theirs”)
Best Practices
-
Backup first if you care about existing uncommitted work
-
Check for merge conflicts—the script tries to resolve automatically, but manual attention is always best for critical merges
-
Review PRs and test your code before deploying
-
Customize for your default branch (
main
vsmaster
) -
Alias it in your shell for even faster use (see below)
How to Make It Yours
-
Script file:
Save it asgit-sync-all.sh
, run with./git-sync-all.sh
-
Alias:
Add to your.zshrc
or.bash_profile
:bashalias gitsyncall='[the one-liner above, all on one line]'
-
Dry-run:
Replace actions withecho
or--dry-run
to preview changes
Want to improve it?
-
PRs welcome! Fork, star, and contribute ideas to the GitHub repo (link your repo if you make one)
-
Try this Gist and share feedback
Spread the word!
Share on Reddit, Hacker News, X, LinkedIn, or wherever devs hang out.
Tag with #git #bash #opensource #automation
git-sync-all
The ultimate all-in-one bash script for Git:
Fetch, sync, stage, commit, merge, push, auto-resolve conflicts, clean, and open PRs—for every branch, in one shot.
Quick Start
Copy-paste to your repo and run:git fetch --all && for branch in $(git branch | sed 's/[* ]//g'); do \
git checkout $branch && \
git pull origin $branch --no-rebase --allow-unrelated-histories || \
(git ls-files -u | cut -f2 | sort -u | xargs -I{} git checkout --ours {} && git add . && git commit -am "Auto-resolve conflicts with ours in $branch" || true); \
git add . && git commit -am "Update $branch" || true && git push origin $branch; \
done && \
git checkout main && \
for branch in $(git branch | grep -v main | sed 's/[* ]//g'); do \
git merge $branch --no-ff -m "Merge $branch into main" || \
(git ls-files -u | cut -f2 | sort -u | xargs -I{} git checkout --ours {} && git add . && git commit -am "Auto-resolve conflicts with ours during merge from $branch" || true); \
done && \
git push origin main && git fetch --prune && git gc && git clean -fdx && \
for branch in $(git branch | grep -v main | sed 's/[* ]//g'); do \
gh pr create --base main --head $branch --title "PR: Merge $branch" --body "Automated PR" || true; \
done
Features
-
Updates and pushes every branch
-
Auto-commits your changes
-
Merges all branches into
main
-
Auto-resolves conflicts (with local version, change to
--theirs
for remote) -
Cleans/prunes/optimizes your repo
-
Opens PRs for every branch with GitHub CLI
Usage
-
Save as a script:
git-sync-all.sh
thenchmod +x git-sync-all.sh
-
Make an alias for your shell
-
For dry-run: use
echo
to print commands instead of running them -
Automatic conflict resolution can overwrite code. Always backup critical repos!
-
Review changes, run your tests, and inspect PRs before merge.
-
You must be logged in with
gh auth login
for PR automation.
Issues and PRs welcome!
3. Gist Description
git-sync-all.sh:
The ultimate Git automation—fetch, sync, commit, merge, push, auto-resolve, clean, and open PRs for every branch in your repo with a single command.See full docs and blog post: thebestblogever.org
Caution: Always backup first and review auto-resolved conflicts.
Paste the script code as the Gist content.
Add tags: git
, bash
, automation
, productivity
, opensource
.
4. Best Practices for Sharing and Adoption
-
Clear documentation in the README and blog post
-
Warnings about overwriting/conflicts so users don’t lose code
-
Multiple ways to use (script, alias, dry-run)
-
Showcase use-cases and output
-
Engage community by inviting improvements/feedback (Issues/PRs)
-
SEO: Use keywords like “all-in-one git script,” “git workflow automation,” “bash git workflow,” etc.
-
Social sharing: Quick intro, what it solves, and link to your repo/blog/gist