I am currently facing the problem that we need to shift to git due some decisions made by other people.
So with mercurial we have the great phases feature, which allows me to manage local branches which will be ignored when a push(all) is issued. The great advantage is, the phases feature is independent from the server hosted master repositories. I can use it on my own locally without permission from anyone.
with git, as far as web search told me, you can add some hooks with branch filtering to common server hosted master repositories. My problem is: as a developer I do not have any control other than create/delete/push/pull. I can not install any hooks there and the people managing the servers will never tinker around with them by hand manually. Everything is managed by an ALM software.
So the solutions for git I found in the Web are not an option for my problem.
This leads to my question: is there any other mechanism in git, which can replace the functionality of mercurial phases, which enables me on a local repository to prevent some branches from ever being pushed to a server hosted repository?
You've always been able to explicitly configure what refspecs get pushed or fetched when you don't give explicit specs on on the command line, and since v2.29 that includes negative matches.
To push all matching branches to origin but not branch notthisone,
git config --unset-all remote.origin.push
git config --add remote.origin.push :
git config --add remote.origin.push ^refs/heads/notthisone
and from then on a plain
git push
will push all matching branches, except not nottthisone
even if it matches.
I see the git push
docs weren't updated to reflect the new feature, push and fetch both use the same engine for handling the patterns, I just tried the above sequence and it works as advertised.
Here's the config file from my test:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "t2"]
url = ../t2
fetch = +refs/heads/*:refs/remotes/t2/*
push = :
push = ^refs/heads/b2