简体   繁体   中英

Git: how can I exclude just one branch from push?

I'd like to continue to push (almost) all branches with a simple git push command, but there are a few things I'd like to be able to keep in Git locally without sharing them with the rest of the world.

The things I'm keeping locally include private changes to public files —hence, I'd like to keep the secret stuff in an appropriately named branch that doesn't get pushed to the server. Is this a thing?

Just create branches in some namespace like private - git checkout -b private/mybranch . As long as that namespace is not existing on the remote repo, any branch in that namespace will not be pushed when you do git push

To also prevent pushing by explicit, set the branch.<name>.remote to some some nonexistent remote.

The only way to push more than one branch at a time is by using push.default = matching, described as : "push all matching branches. All branches having the same name in both ends are considered to be matching." That's the default setting, so maybe what you're used to. You can have a branch not pushed by naming it something that doesn't exist on the remote you're pushing to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM