I can't push my code and keep getting the same error no matter what I do

本小妞迷上赌 提交于 2020-12-29 14:07:24

问题


I'm trying to push my code to my remote branch but keep receiving this error:

! [rejected] (non-fast-forward)
error: failed to push some refs to 'git@github.com:
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details

I think what may have caused this was the fact that I fixed a typo in my README.md on github instead of through my local environment.

I've looked all over stack overflow and tried the commands they mentioned for this problem such as git pull , git pull --rebase , git pull origin master , git push --f and many others with no avail.

I've also tried the answers in the following questions, with no success:

Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g [duplicate]

Cannot push to GitHub - keeps saying need merge

Git pull a certain branch from GitHub

I also tried git pull upstream master and I get this error:

fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

回答1:


Problem resolved:

I added another change and saved it in my local environment and did the following:

git stash

git pull origin <branch-name> -v

git add .

git commit

git push origin <branch-name>




回答2:


Based on your description I have the assumption that you are on a different branch that was derived from master, and master is set to track origin/master.

Try switching back to it first:

git checkout master
git fetch
git pull origin master

You might have to merge your changes as there has been a new commit on the remote and you have something new on your side as well.




回答3:


First of all use command to take backup of your code : git stash.

Then use command git pull or git pull upstream master if you have any upstream set (I assume you have).

Merge the changes from master to your local Git merge upstream/master.

git push

Now if you open your branch in browser you will see the message that “your branch is in sync with master”. ** It should always remain in sync. **

Now use command git stash pop to get back your changes and commit.



来源:https://stackoverflow.com/questions/54394491/i-cant-push-my-code-and-keep-getting-the-same-error-no-matter-what-i-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!