16

I am used to using SVN and only recently switched to GitHub.

I am trying to update some files in a GitHub repo, but I get this message:

To https://github.com/.../
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://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 have tried commands like git fetch origin and git pull, but none of these make it so my current branch is not behind.

In SVN I'd just do svn update and then commit my changes.

I've also tried git pull origin, but I get a strange text message popping up and I have no idea how to interface with it: Updating a local repository with changes from a Github repository

Community
  • 1
  • 1
user3898238
  • 957
  • 3
  • 11
  • 25
  • Usually `git pull` will merge the commits from the remote so that your branch isn't behind and allow you to push. What is the output of `git remote -v` and `git branch -vv`? – Justin Howard Nov 18 '14 at 01:40
  • I manually fixed it by cloning and copying my changes in. I've tried `git pull` before, but it asks to clarify the branch name I'm pulling from. If I do `git pull origin`, an EMACs-like file opens, asking to explain why I'm merging. – user3898238 Nov 18 '14 at 01:50

2 Answers2

36
  1. Check your current branch with the command:

    git branch

    It will show your current branch name with an asterisk (*) next the name.

  2. Then update your local branch with the remote branch:

    git pull origin branchname (This is the branch name with asterisks)

  3. Now you can push your code to the remote repository if you have already committed your local changes with the command:

    git push origin branchname

If you haven't committed yet, first do a commit and then do a git pull and push.

Kevin Bowen
  • 1,625
  • 2
  • 23
  • 27
Breen ho
  • 1,601
  • 14
  • 23
5

It is normal for git to open an editor when you pull. This is because you are merging in the changes from the remote to your local branch.

When you pull, git detects whether it needs to merge your local branch with the remote branch. If it needs to merge, it will do so and present you with the opportunity to write a custom message for the merge commit. At that point, you can choose to just close the editor, and git will finish the process.

Basically, all you had to do is close the editor and you would have been done.

Essentially, git is doing the following:

#Download all the commits from the remote
git fetch origin

# Merge in the commits from the remote to your local branch
# If anything needs merging, this will open a text editor
git merge origin/master master
Justin Howard
  • 5,504
  • 1
  • 21
  • 48