-1

my friend and I, we were making some kind of project and we used GIT for our versioning software, but after I pulled his code from the gitlab, and made few changes and commited that changes, I wanted to push back to gitlab, but when then, this warning and error:

warning: redirecting to https://gitlab.com/Sanady/project.git/
To https://gitlab.com/Sanady/project
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitlab.com/Sanady/project'
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.

Is there any fix? I tried to push repo by flag -f (force) but still that was not working...

Sanady_
  • 68
  • 10
  • 1
    Here, you have no choices but to `pull` first and merge conflicts before pushing – Derlin Aug 10 '20 at 06:44
  • So I have to make merge with master, right? – Sanady_ Aug 10 '20 at 06:47
  • before committing, do a ```git pull --rebase```. Commit your changes and then push – awadhesh pathak Aug 10 '20 at 06:50
  • warning: redirecting to https://gitlab.com/Sanady/project.git/ There is no tracking information for the current branch. Please specify which branch you want to rebase against. See git-pull(1) for details. git pull If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/ master This are errors: – Sanady_ Aug 10 '20 at 06:58
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+tip+of+your+current+branch+is+behind – phd Aug 10 '20 at 22:00

2 Answers2

0

This error means you friend committed some changes between the time you pulled and the time you committed your changes.

Hence, you need to pull the changes first, resolve the conflicts and then you can push:

git pull
# resolve conflicts (see git status)
git commit # commit merge
git push # now it works
Derlin
  • 9,572
  • 2
  • 32
  • 53
  • I tried that too, but there is still error when I want to pull : warning: redirecting to https://gitlab.com/Sanady/project.git/ 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 If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/ master – Sanady_ Aug 10 '20 at 07:04
  • so if you are using branch master on remote, run `git branch --set-upstream-to=origin/master master` once, or always add `master` to the end of the commands. e.g. `git pull master`, `git push master` – Derlin Aug 10 '20 at 07:05
0

Assuming, there is no permissions issue or something (I'm not familiar with gitlab),

It looks like your friend also committed the change to master, hence your local changes do not include his work. So should do the following first:

// Note, make sure you don't have uncommitted files:
git status 
// now run the following:
git pull --rebase

This will pull your friend's changes and place your local commits on top of that. Note, if you and your friend were touching the same files, you might run into "conflict resolution". Git Doesn't know how to apply both of your and your friend's changes "next to each other" on the same file.

Assuming there was no conflicts like this:

Then you can try to push:

git push
Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
  • error: cannot pull with rebase: Your index contains uncommitted changes. error: please commit or stash them. These are errors which I get when I try to do rebase – Sanady_ Aug 10 '20 at 06:54
  • Also there is this error: The following paths are ignored by one of your .gitignore files: node_modules hint: Use -f if you really want to add them. hint: Turn this message off by running hint: "git config advice.addIgnoredFile false" – Sanady_ Aug 10 '20 at 06:55
  • run `git status` first as I suggested. It should not show any files colored with "green" or "red". If it is, these are changes that you've done locally and have not committed yet, decide what to do with them first, throw them away or commit. In any case don't run`git pull --rebase` before you decide on those files. – Mark Bramnik Aug 10 '20 at 06:57
  • I added every change, then I commited that changes here is log: $ git status On branch master nothing to commit, working tree clean – Sanady_ Aug 10 '20 at 07:00
  • Okey somehow I managed to get rebase downloaded, but there are conflicts, how should I fix them? – Sanady_ Aug 10 '20 at 07:08
  • Somehow I managed to this solution working, how I don`t know to be honest.. but somehow it is working I had to rebase master branch from the gitlab.. – Sanady_ Aug 10 '20 at 07:58