简体   繁体   中英

How can I solve “Updates were rejected because the tip of your current branch is behind”?

I want to push to github. I am using SourceTree.

When I push, I get an error like this:

错误

How can I solve this problem?

The graph on SourceTree is like this:

图形

If I pull, it displays an error too like this:

拉

In your screen shot you can see 3 commits, two commits are connected, test and remove test, but then your newest commit does not have a parent, hence no related histories.

Option 1 ( origin/master has no useful code)

Judging by the commit messages, you have an empty repo before your latest commit. In this situation, I would force replace what is on remote by doing git push -f .

Please note this will delete the commits labeled test and remove test .

Option 2 ( Keep origin/master )

Use git cherry-pick those commits into your local master. Always do this oldest to newest.

git cherry-pick <commit hash>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM