I am maintaining a branch in a git repo (the local/remote in the diagram). The code I worked on in the local version of the branch actually belongs in the other branch (Branch 2 in the diagram).
Unfortunately, while I had not pushed my local commit of the branch, another developer pushed their version which created the situation in the original diagram.
In order to attempt to fix it, I rebased my local copy onto Branch 2. However, my local copy is still associated with it's original remote branch.
I would like to associate it with Branch 2 and then push, to get the outcome in the desired diagram.
How can I achieve this?
If you want to push a local branch to a branch with different name, you just do git push remoterepo localbranch:remotebranch
.
If you need to change the upstream, use git branch --set-upstream-to=remotebranch localbranch
.
As this question is tagged with "gitkraken" here is how you do it in GitKraken:
If you want to push your local branch to a different remote branch only once you can drag and drop your local branch on the remote branch and select "Push local to origin/remote".
The explanation on the GitKraken site: https://www.gitkraken.com/learn/git/problems/git-set-upstream-branch#:~:text=With%20GitKraken%2C%20it's%20easy%20to,push%20instead%20of%20setting%20upstream .
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.