Eris
Eris

Reputation: 150

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?

Upvotes: 5

Views: 2901

Answers (2)

manojlds
manojlds

Reputation: 301147

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.

Upvotes: 9

Ryan Stewart
Ryan Stewart

Reputation: 128829

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.

Upvotes: 2

Related Questions