Problem using Git basic commands - push #22054
-
Hello everyone, my name is Billy and am a student studying BSc. business intelligence. I have just started an online course about Front-End Web Development. First week course is about setting up Git and using basic Git commands. As you see from the screenshot, I commited four changes and would like to push these changes to my remote repository. However, this command is rejected. The error message hints to use “git pull” and I tried, terminal gave me another error: Does anybody knows how I can solve this problem, so that the changes can be pushed to the remote repository? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
The “refusing to merge unrelated histories” message means that your local and remote repositories have absolutely no commits in common. That can mean a few things:
I’ll assume the second case here, but the third one can be handled the same way.
Decide what you want to keep. That can be just one version (I’d guess the local one). If you also want to keep a few commits from remote you can use Once you have a branch that you are absolutely sure contains what you want to keep, you can force-push ( Theoretically you can also tell git to merge despite the unconnected histories, but that is almost always the wrong choice (which is why git refuses do to it by default). |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your feedback. I checked the commit logs of my local and my remote branches. I would like to keep my local one, that also means, I would like to push the local one to the remote repository. Do I need to tell the terminal which version (in my case the local one) I will keep? Because when I did git push --force right aright, it shows the following error: |
Beta Was this translation helpful? Give feedback.
-
Each branch in a git repository can have a remote “upstream” branch (also called “tracking” branch). If you do a If you want to set
If you don’t want to set the upstream branch leave out the |
Beta Was this translation helpful? Give feedback.
-
Thanks for the explanation! I tried the git push --force --set-upstream origin master command and problem was solved immediately. Now all commits in my local repository was synchronized to my remote repository. Honestly I don’t completely understand how it worked (and did not work)… but still thank you so much! |
Beta Was this translation helpful? Give feedback.
Each branch in a git repository can have a remote “upstream” branch (also called “tracking” branch). If you do a
git pull
orgit push
(force or not) without further parameters it will pull from or push to there. The error message says that your local master branch doesn’t have a configured upstream branch.If you want to set
origin/master
as the upstream branch for your localmaster
, you can just use the command suggested by the error message, and add--force
for the force-push:If you don’t want to set the upstream branch leave out the
--set-upstream
option.