Set up git to pull and push all branches
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Git does not provide a single safe command that pulls and pushes every branch the way many people expect. git pull only updates the current checked-out branch, and git push only sends refs you explicitly select or that match your push configuration, so full multi-branch sync has to be handled deliberately.
Understand What Git Can and Cannot Do
The first step is separating three different operations:
- '
git fetchdownloads remote refs and objects.' - '
git pullfetches, then merges or rebases the current branch.' - '
git pushupdates remote refs from local refs.'
If your goal is "see every remote branch and update my remote view," use fetch:
--prune removes stale remote-tracking refs, which keeps branch lists from drifting over time.
Create or Verify Tracking Branches
Fetching does not automatically create a local branch for every remote branch. If you want local branches that follow remote ones, create them explicitly:
To inspect existing upstream relationships:
If a local branch exists but is not tracking the right remote branch, fix it:
That upstream metadata matters because it controls what plain git pull and many push operations actually target.
Push All Local Branches Only When You Mean It
If you really do want to publish every local branch to origin, Git supports that:
This is useful in mirror-like environments or personal backup remotes, but it is risky in a team repository where you may have scratch branches that should stay private. For normal collaboration, pushing only the branches you actively maintain is usually safer.
If you need a true mirror of all refs, there is also:
That is much more aggressive because it mirrors branch and tag deletions as well. It is appropriate for repository mirroring, not everyday development.
Use a Safe Multi-Branch Workflow
A practical routine for many repositories is:
- Fetch everything with prune.
- Inspect which local branches track which remotes.
- Update important branches one by one.
- Push only the branches that should be published.
- Push tags separately when release metadata matters.
Helpful inspection commands:
These commands make it obvious when a branch has no upstream, is ahead of remote, or points somewhere unexpected.
Configure Conservative Defaults
Some global settings make multi-branch work more predictable:
push.default simple is intentionally conservative. It pushes the current branch to its upstream instead of trying to guess broader intent.
Common Pitfalls
- Expecting
git pullon one branch to refresh every other local branch. - Running
git push origin --allwithout checking for temporary or experimental branches. - Forgetting to configure upstream tracking, which makes pull and push behavior inconsistent.
- Using
--mirroron a normal collaboration remote and unintentionally deleting refs. - Treating tags as automatic when your workflow actually requires a separate
git push --tags.
Summary
- Use
git fetch --all --pruneto refresh your view of all remote branches. - Remember that
git pullonly updates the current branch. - Create and verify tracking branches explicitly with
git switch --trackandgit branch -vv. - Use
git push origin --allonly when publishing every local branch is genuinely intended. - Prefer conservative Git defaults over broad automatic sync behavior.
Related reading
- Set Visual Studio Code to be global Git editor on OSX
- setting tabwidth to 4 in git show / git diff
- Setting up and using Meld as your Git difftool and mergetool
- Should a repository interface expose a clear() method to clear the cache of the implementation?
- Should composer.lock be committed to version control?
- Should Gemfile.lock be included in .gitignore?
- Should I add the Visual Studio 2015 .vs folder to source control?
- Should I be adding the Django migration files in the .gitignore file?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.