Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

! [rejected] master -> master (non-fast-forward) on a new up-to-date branch

In my repo, I have a master branch, and a new branch.

I've been working on new for a while, making commits, and pushes as I go. I decided now to branch off new and call it newest. So I did

git checkout -b "newest"

and the branch was successfully created. I added a file, and started working on it. I committed my changes a couple of times.

BUT when I try to push this new branch and my changes to it to origin, I get this error:

C:\wamp\www\myproj>git push origin
To https://github.com/Imray/Proj.git
 ! [rejected]        master -> master (non-fast-forward)
 ! [rejected]        new -> new (non-fast-forward)
error: failed to push some refs to 'https://github.com/Imray/Proj.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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. 

So, as specified in the instructions, I tried git pull, but then I got:

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> newest

I'm stuck.

How do I push my new branch and the changes to github?

like image 853
CodyBugstein Avatar asked Nov 01 '22 12:11

CodyBugstein


1 Answers

Check your git config push.default. It might be on "matching", since it tries to push all existing branches.
That was the default before Git 2.0+.

I would recommend setting it to "simple", in order to push only the current branch.

That being said, to push a branch, you need (for the first push) to setup an upstream branch.

For a branch never pushed before:

git push -u origin newest

For a branch which does exists on the upstream repo:

git branch --set-upstream-to=origin/master master
git branch --set-upstream-to=origin/new new

Then a git checkout master ; git pull would work.

like image 149
VonC Avatar answered Nov 09 '22 15:11

VonC