问题
I am new to git and not super tech savvy when it comes to it. I use source tree to commit and push code. I am running into strange issues which I never did before. When I merge my branch to the master I get this "Unable to merge, unrelated branches".
Moreover, I see strange things in my repo:
- The remote and the locals don't seem connected at all
- I keep getting prompted for authentication but that username is wrong and I can't find a way to change it:
Any help in this regard would be great!
回答1:
When you push a new branch to a remote, you need to set the local branch to track the remote branch. Sometimes it's automatic, it depends on your Git config.
With the command line, you would do this with the -u
argument.
For example: git push origin HEAD -u
means: push the current branch (where HEAD is) to remote origin and set the local branch to track the remote one.
With Sourcetree, I just checked the UI, and you have a track option. Make sure this is checked when you push a new branch to a remote.
Regarding your current situation, you could manage to set all branches correctly but you mentioned you don't know git very well. I don't want you to lose anything.
Checking this answer may help you: Make an existing Git branch track a remote branch?
What you could do, without dealing with Git commands:
- only if all your work is on the remote!
- delete the local branches (do not delete the remote ones!).
- then pull the remote ones. Normally, Git will automatically set the local branch to track the remote branch when you checkout a remote one.
I highly recommend that you take some time to learn Git:
- https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches
- https://learngitbranching.js.org/
来源:https://stackoverflow.com/questions/48837176/unable-to-merge-unrelated-branches-in-bitbucket