Shaohao
Shaohao

Reputation: 3511

Git revert / reset commits to match remote repo

I am doing open source contribution on Github, still fairly new to using command line to performance git actions.

My situation now is:

I made a pull request to an open source project with 10 commits. The pull request hasn't been approved yet. That means I am 10 commits ahead of remote open source master.

What I want to do is:

I want my remote repo and local repo matches the remote open source repo. So that I can contribute to other features because the new feature does not rely on the new code.

My question is:

What should I do in this case? Revert the commits or make a new repo from open source project?

Thank you in advanced.

Update:

I had created a new branch for new feature development. And I merged the branch to my master.

Upvotes: 0

Views: 2189

Answers (1)

Atri
Atri

Reputation: 5831

Since you created a branch from remote master, and merged the new branch to master after some commits, your local master is ahead of remote master. You need to reset your local master to remote master.

There are various ways of doing it. As you mentioned, one is to revert all the commits, which I don't recommend. Here are a couple of ways (#2 is easier):

  1. First checkout from the SHA of the last commit in the remote repo: git checkout <sha>

You can get the sha by doing a git log and checking the last commit not done by you. That commit will have a unique identifier(SHA).

-OR-

  1. You can do a reset to the remote repo's master branch using: git reset origin/master

Then do git checkout -b branch_name

This way you don't have to revert your commits and once your new feature is done, you could merge your branch_name branch to master and request a pull.

Upvotes: 1

Related Questions