1

when I try to push to master im getting error

https://github.my.corp/i64444/app.git ! [rejected]
HEAD -> refs/for/master (non-fast-forward) error: failed to push some refs to 'https://github.my.corp/i64444/app.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.

I read the following post Cannot push to GitHub - keeps saying need merge and try to do the git push -f origin master which doesnt help , I got message that everyting is up to date , any idea?

I did also before git reset --hard origin master (fetch & rebase also)which doesnt help either...,any idea?

The output of the pull

 * branch            master     -> FETCH_HEAD
Already up-to-date.

The output of the git status is:

HEAD detached from ea82585
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .idea/

nothing added to commit but untracked files present (use "git add" to track)

The number ea82585 is the number of the latest commit in the master...

Community
  • 1
  • 1
NSS
  • 755
  • 1
  • 11
  • 30
  • what is the output of `git status`? – Francesco Apr 12 '16 at 12:02
  • @Francesco - done please have a look – NSS Apr 12 '16 at 12:08
  • You are on a detached HEAD, which means, you didn't checkout a branch, but a specific commit. If you already have committed some changes, use "git log" to get the commit hashes, write them down, checkout the branch you want, and then cherry pick or merge your commits there. – dunni Apr 12 '16 at 12:11
  • 1
    Tip: add ".idea" to your .gitignore file. You (or a co-developer) WILL regret it if you don't. – Creynders Apr 12 '16 at 12:28
  • @NinaS : Does the answer help you with your question? or are you still having problems? – dubes Apr 13 '16 at 10:36

1 Answers1

2

From your git status output:

HEAD detached from ea82585

It seems that you have checked out a commit instead of a branch. Thus git is unable to track your current commit to a remote branch. Once you enter what is called a detached head state git will be stuck at a commit and thus do nothing when you pull or push. Check out this answer for more details on detached head.

If git is able to track your local branch to your remote repository, you will see git status output as something like:

$ git status 
On branch dev 
Your branch is up-to-date with 'origin/dev'.

How to fix it

Essentially you will have to move your commits to a branch that Git can track. You can do this by:

git commit -m "....."
git branch my-temporary-work
git checkout master
git merge my-temporary-work

Copied from this answer

Community
  • 1
  • 1
dubes
  • 5,324
  • 3
  • 34
  • 47