0

I have a repo that has only one file (a Jupyter notebook file). Since the file was created using Google Colab, it didn't exist in my local repo, but was only on my GitHub repo.

I just added a README file and was trying to push from my local repo to GitHub. But since the remote repo was ahead of my local one, I wasn't able to push after committing.

I then decided to pull, but since I was not familiar with the syntax, I didn't specify any parameters after git pull. Then I tried again with git pull origin master, but now I got an error message saying there's a bug, and the repo name changed to "master|MERGING"...I know I probably need to pull the remote into a new local branch and merge it with my master branch, but I don't know how to do it here and also am scared to mess up the whole thing... Thanks for any tips!

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git commit -m "Add README file"
[master 13c0b76] Add README file
 1 file changed, 16 insertions(+)
 create mode 100644 README.md

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git push origin master
To https://github.com/georgeliu1998/tf_and_colab.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/georgeliu1998/tf_and_cola                                                                                                                                                                                               b.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git checkout master
Already on 'master'

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git pull
remote: Enumerating objects: 20, done.
remote: Counting objects: 100% (20/20), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 18 (delta 5), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (18/18), done.
From https://github.com/georgeliu1998/tf_and_colab
   0a500ee..1238317  master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master


georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git push origin master
To https://github.com/georgeliu1998/tf_and_colab.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/georgeliu1998/tf_and_cola                                                                                                                                                                                               b.git'
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.

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git remote
origin

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git pull origin
You asked to pull from the remote 'origin', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git pull origin master
From https://github.com/georgeliu1998/tf_and_colab
 * branch            master     -> FETCH_HEAD
hint: Waiting for your editor to close the file... warning: failed to restrict f                                                                                                                                                                                               ile handles (2)

handle #0: 0000000000000434 (type 3, handle info (1) 0
handle #1: 0000000000000438 (type 3, handle info (1) 1

This is a bug; please report it at
https://github.com/git-for-windows/git/issues/new

To suppress this warning, please set the environment variable

        SUPPRESS_HANDLE_INHERITANCE_WARNING=1

error: cannot spawn C:/Users/georg/AppData/Local/atom/bin/atom.cmd: No such file                                                                                                                                                                                                or directory
error: unable to start editor 'C:/Users/georg/AppData/Local/atom/bin/atom.cmd'
Not committing merge; use 'git commit' to complete the merge.

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master|MERGING)
$ git push origin master
To https://github.com/georgeliu1998/tf_and_colab.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/georgeliu1998/tf_and_colab.git'
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.

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_colab (master|MERGING)
$
George Liu
  • 3,601
  • 10
  • 43
  • 69
  • Please don't post screenshots of text. Any text your question depends on needs to be copied into the question as human- and machine-readable text, not screenshots. – user229044 Dec 18 '18 at 18:00
  • Done. Can you confirm it's ok now? thanks@meagar – George Liu Dec 18 '18 at 18:06
  • Possible duplicate of [Cannot push to GitHub - keeps saying need merge](https://stackoverflow.com/questions/10298291/cannot-push-to-github-keeps-saying-need-merge) – phd Dec 19 '18 at 00:10
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+tip+of+your+current+branch+is+behind – phd Dec 19 '18 at 00:10

2 Answers2

1

What's happened is that you have made changes locally to the branch when it was behind remote. So when you committed locally, you created a new reference that was out of sync with the order of commits on the remote server.

origin/master: * -> * -> *
local/master:  \__ -> your commit

If it's just one commit you need, check out a new branch to save the current state

git checkout -b temp-updates

Then copy the commit hash from the first line of git log

commit 166a17b4852f5b83a09c3198169d86959a68e3dd

Then switch back to master and reset it to be the same as your remote branch:

git checkout master
git reset --hard origin/master

Now you can cherry-pick the commit with the changes you made:

git cherry-pick 166a17b4852f5b83a09c3198169d86959a68e3dd

Now you should be able to cleanly push

git push origin master
codenamev
  • 2,203
  • 18
  • 24
0

git pull equals git fetch plus git merge. When in doubt do not call git pull, instead call git fetch and then git status and stop to think what you want to do next.

In your case the subsequent git merge tried to merge the changes from origin/master with the changes in your local master, but it resulted in a conflict. git is expecting you to solve the conflict, and then git add the file to mark it as solved, and git merge --continue to complete the merge.

If you want to abort the merge you can do git merge --abort to go back to the normal status. If that command does not work, for whatever reason, a git reset --hard HEAD will clean your working directory. WARNING: git reset --hard will undo any non-commited change to your files!

rodrigo
  • 94,151
  • 12
  • 143
  • 190