moses toh
moses toh

Reputation: 13182

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:

error

How can I solve this problem?

The graph on SourceTree is like this:

graph

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

pull

Upvotes: 0

Views: 250

Answers (1)

John Pavek
John Pavek

Reputation: 2665

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>

Upvotes: 1

Related Questions