29

I'm getting that error with a PR, but when I git status it says nothing to commit, working directory clean.

That's on the branch with the PR.

On branch pr12
nothing to commit, working directory clean

2 Answers 2

23

git status tells you about the state of your working directory tree and your index (where staged changes live) relative to the latest commit on the current branch. The output you're seeing means that the files on your disk exactly match the latest commit on your branch. That is, there's "nothing to commit".

The message from GitHub is not about committing, but about merging. GitHub would like to offer you a one-click method to merge this branch into your master branch, but it can't, because that merge results in conflicts. Since GitHub doesn't have a way to help you resolve conflicts though the website, it asks you to resolve them on your own machine.

The best way to deal with this situation is to merge the current master branch into your topic branch locally and then push the result to GitHub. To do that, do the following:

$ git checkout pr12  # If you're not already on pr12
$ git fetch origin
$ git merge origin/master

(I'm assuming that the GitHub remote is called origin. It typically is, and you probably know if it isn't.)

First we make sure we're on the right branch. Then we make sure we have the latest code from the master branch on the GitHub repo. Then we merge that code into our pr12 branch.

Remember: git fetch origin updates our local origin/master to be the same as GitHub's master, but it doesn't touch the local branch called simply master. We'd have to checkout our master branch to make changes to it. Instead, we just update our idea of what's on GitHub (origin/master) and merge that into our pr12.

When you run the merge command, you'll see conflicts. Those represent decisions that git (and GitHub) couldn't make automatically. Edit those files so they're the way you want them to end up. Then:

$ git add each/file.txt that/had/conflicts.conf
$ git commit   # Your editor will open with a pre-filled
               # commit message. Just save and close the file.
$ git push origin pr12

That is, we add the versions of the files that we fixed, then finish the merge commit we started with git merge. Lastly, we push the branch with the new merge commit up to GitHub.

Since we've resolved the conflicts, this branch should be trivial to merge the other way, into master. GitHub will notice that, and give you a green "Merge" button.

4
  • After I did git merge origin/master pretty much every file says "both added" and "new file".
    – Nathan
    Oct 7, 2014 at 17:32
  • That's odd. Git's telling you that, since the point it time where origin/master and pr12 diverged, both branches have added those files. You can find where they diverged visually using git log --graph --oneline origin/master pr12. Does the output of that command look like what you expect the history of those two branches to look like?
    – Peeja
    Oct 7, 2014 at 17:44
  • So I've somewhat got it. But now everything from the original repo which got merged with the forked repo appears in the branch. And when I try to revert that one commit, it says something about the -m switch.
    – Nathan
    Oct 7, 2014 at 18:56
  • By "repo" here, do you mean "branch"? You want everything from the original (master) branch to be in pr12. That means it's up to date. (The error about the -m switch is because you're trying to revert a merge commit and go back to its parent, but merge commits have multiple parents: the commits you merged together. The -m switch lets you pick which one you want to revert to.)
    – Peeja
    Oct 7, 2014 at 19:24
10

When I encountered this message, it was because my fork of a particular repo was behind the original. In my particular case the repo I'd forked is pydata/pandas.

I had to configure a remote for my fork by doing:

> git remote add upstream [email protected]:original_user/original_repo.git
> git remote -v
origin  [email protected]:some_user/pandas.git (fetch)
origin  [email protected]:some_user/pandas.git (push)
upstream    [email protected]:pydata/pandas.git (fetch)
upstream    [email protected]:pydata/pandas.git (push)

(Note: git remote add upstream is a git's way of saying "Add a remote called "upstream". The name can be anything.)

Then I fetched the latest commits from the original repo with:

> git fetch upstream
> git checkout master # Just in case you're not already on master
> git merge upstream/master

and finally push the merged repo back to github:

> git push
1
  • Thanks! I've searching for a while and this resolves my problem Sep 24, 2020 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.