2

I have a git repo with a master that is set up in upstream, and a dev branch which is getting every stream from this master.

I have some commited changes on my dev branch that are useful only for this specific branch and not for the master, and I

my current branch is :

git status
On branch dev
Your branch is ahead of 'master' by 2 commits.

my commits are visible when I do

git diff origin/master..HEAD

my branch is up to date ( and goes through master as it was doing before) :

git pull
From .
 * branch            master     -> FETCH_HEAD
Already up-to-date.

But when I push, I got bashed :

git push origin
To https://my_git.git
 ! [rejected]        dev -> dev (non-fast-forward)
error: failed to push some refs to 'https://my_git.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.

Any tips would be appreciated, I had a look on several posts like this : git push rejected non-fast-forward or this Git non-fast-forward rejected , but none of them seems to work in my case.

Thanks

Community
  • 1
  • 1
Nicolas D
  • 1,182
  • 18
  • 40
  • 1
    You (or rather your git client) are trying to push branch dev to the server, which apparently can not be fast-forwarded. So you should either do `get fetch dev` and rebase, or just push the master branach with `git push origin master` – Benno Jan 07 '16 at 17:12
  • does the `dev` branch already exist? A `git fetch origin dev && git status` would be helpful. – mbb Jan 07 '16 at 17:15
  • when i do git fetch dev i got fatal: 'dev' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. but in fact, i am already on my dev branch so it is existing and my user can access to it. Any idea? – Nicolas D Jan 07 '16 at 17:15
  • git fetch origin dev From https://my_git * branch dev -> FETCH_HEAD – Nicolas D Jan 07 '16 at 17:16
  • git checkout master git push origin master Everything up-to-date – Nicolas D Jan 07 '16 at 17:18
  • @mjb git status is on the question, so yes dev branch is up and running – Nicolas D Jan 07 '16 at 17:20
  • @Benno I did tried both, and nothing works :s any other idea? – Nicolas D Jan 07 '16 at 17:20
  • Possible duplicate of [Git non-fast-forward rejected](http://stackoverflow.com/questions/5667476/git-non-fast-forward-rejected) – Andrew C Jan 07 '16 at 18:57

1 Answers1

1

Your problem is here:

git push origin 

You did not specify any branch to push.
Assuming you are using git <2.0 you must set the branches that you wish to pull/push. In your case its trying to push ALL your branches and one of them generate the error.

This will for it for you

# get all latest changes from the remote
git fetch --all

# merge the changes to the local repository
git pull origin dev 

# push the changes to the remote
git push origin dev

Git v2.0 Release Notes

Backward compatibility notes

When "git push [$there]" does not say what to push, we have used the traditional "matching" semantics so far (all your branches were sent to the remote as long as there already are branches of the same name over there).

In Git 2.0, the default is now the "simple" semantics, which pushes:

  • only the current branch to the branch with the same name, and only when the current branch is set to integrate with that remote branch, if you are pushing to the same remote as you fetch from; or

  • only the current branch to the branch with the same name, if you are pushing to a remote that is not where you usually fetch from.

You can use the configuration variable "push.default" to change this. If you are an old-timer who wants to keep using the "matching" semantics, you can set the variable to "matching", for example. Read the documentation for other possibilities.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • I tried also to do " git push origin dev ", and I got the same error, so obvioulsly it is coming from my dev branch and not the upstream behind, but I still can't solve it and push correctly – Nicolas D Jan 07 '16 at 18:06
  • 1
    Try this: `git pull origin dev && git push origin dev` – CodeWizard Jan 07 '16 at 18:08
  • @CodeWizard I read somewhere that is it also cause by when you initialized local repository with git init, what is this – blackHawk Nov 27 '16 at 12:14