Reputation: 29332
I have a local BitBucket server, and I merge my changes into master from the web UI. I'd like to work with a permanent personal branch, that I will periodically create merge requests from.
I'd like git pull
to merge origin/master
into my local master
, and git push
to push my local master into origin/itsadok
. I will then create a merge request on the server, and merge my changes from origin/itsadok
into origin/master
.
BitBucket server: origin/itsadok --- via PR --> origin/master
↑ |
Local machine: \---------- master <---------/
Seems simple enough.
I know I can manually do git push origin master:itsadok
, but I'd like it do be the default. It seems that the only way to set the default push target is to config branch.master.merge
to refs/heads/itsadok
(and config push.default
to upstream
), but then pull will merge from my personal branch as well.
Is there a way to configure git so that the default push and pull will work as described above?
Edit: It occurred to me that I can achieve something very similar by setting push.default
to current
, naming the local branch the same as the remote personal branch, and setting branch.itsadok.merge
to refs/heads/master. In other words:
BitBucket server: origin/itsadok --- via PR --> origin/master
↑ |
Local machine: \---------- itsadok <--------/
This almost works, but because I have scripts that assume my local branch is called master
, this solution is rather inconvenient for me. If there are no other idea, though, I'll settle for this.
Upvotes: 2
Views: 88
Reputation: 3153
You can achieve described behavior by proper mapping of push refspecs. As described in push manual, git looks on what to push in the following order:
remote.<remote_name>.push
configuration if not emptypush.default
configuration otherwiseSo you can make master
tracking origin\master
, so pulling works fine, and then configure remote.origin.push
, so push without arguments fits your workflow:
git config remote.origin.push refs/heads/master:refs/heads/itsadok
You can check your configuration by printing upstream branch with git rev-parse --symbolic-full-name @{upstream}
and push branch with git rev-parse --symbolic-full-name @{push}
However, there are couple of caveats:
git status
will compare master with its upstream, so you will see "1 commit ahead" notification even after commit is actually pushed.git push
without arguments, while on non-master branch will still push data from master to itsadok. If you want to try fixing this, probably the best way to start is refspec configuration examplesUpvotes: 1