Git track different branches for push and pull?

345 views Asked by At

I have a Git repository which is being managed with Gerrit, where you don't push to <branch>, but instead push to refs/for/<branch>, and then magic happens. Thus, I'd like different behavior for git pull and git push. In particular, I want git pull to pull from <branch>, but git push to push to refs/for/<branch>. Is it possible to set this up in Git?

(Note: this has been asked before, but the answer was simply, "no, but here's how you can make Git force you to always specify the refspec so you'll never accidentally push to the wrong branch," which isn't the answer I'm looking for)

1

There are 1 answers

1
phd On BEST ANSWER

I use the following configuration:

 git remote add review ssh://[email protected]:29418/repo
 git config remote.pushDefault review
 git config remote.review.fetch master:master
 git config remote.review.push master:refs/for/master

I.e. add remote named review, set default push remote for all branches to review, configure fetch/pull for master from remote branch master, configure push for master to remote branch refs/for/master.