How to configure git put push only some branches and ignore others?
I want to prevent some git private branches from being pushed upstream.
How can I achieve this?
- When I do “git push”, what do the statistics mean? (Total, delta, etc.)
- Have remote git repository refuse merge commits on push
- git pull analogous to / opposite of git push -f?
- How to fix a deleted git commit branch or refs?
- How to update the repository with unaccepted pull requests?
- How I can update changes on remote git repository?
Any of the folowing kind of solutions would be acceptable:
- push only branches in a list
- skip pushing branches in a list
Update: currently my push configuration is using
mirror=true, which means that will push all branches.
Explanation, we do have an internal centralized repository inside the company which is mirrored to github. We do want to get all braches to the company-repository, which is already happening but I do want to be able to limit what goes to public to github, so not all branches will go public.
The problem is that now everything goes to github, probably due to the mirror option. If I remove it it will probably push only the branches that do already exists on github.
Still, even this option is not what I want, as I want to be able to control which ones are to be skipped or included.
If this can be done using a regex pattern, the better.
2 Solutions collect form web for “How to configure git put push only some branches and ignore others?”
Set push policy to upstream:
git config --global push.default=upstream
(If you just want it for a single repo and not for all repos on your machine, skip the
Then, make sure the private branches have no upstream branch set (that would probably be the case if you haven’t set it up manually)
git branch -vv
If there are any remote tracking branches, remove them with:
git branch -d -r origin/<remote branch name>
You’ll need to decide whether you really want to mirror or not. If you really want to mirror, then all refs will be pushed by an unadorned
git push or
git push <remote>. You can still do
git push <remote> <localbranch>:<remotebranch>, but if you want to push a bunch of branches that can get tedious unless you script it, and even then, if the set of branches you want to push changes often, it can still be a pain.
Probably your better option is to turn mirroring off, and explicitly set up in
.git/config the branches that you do want to push, as well as a suitable default mode for when you do a
git push without specifying branches. pgilmon’s answer gives one possible setting for that default – read the documentation to decide if that’s the most useful default mode for you (newer versions of
git offer more different modes for that default, as well as implementing a different “default default” if you don’t specify one).