Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Can't push to github #387

Closed
kjkaal opened this issue Oct 22, 2016 · 34 comments
Closed

Can't push to github #387

kjkaal opened this issue Oct 22, 2016 · 34 comments

Comments

@kjkaal
Copy link

kjkaal commented Oct 22, 2016

Hello,

I am unable to push my HW_5 to github. I am getting an error message saying the following
To https://github.com/STAT545-UBC/kaal_katrin-julia.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/STAT545-UBC/kaal_katrin-julia.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.

I think it may be related to removing a file on github labeled Rapp.history earlier today.
I have no iead how this file ended up on github and removed it to keep my repo clean.
I didn't pull before trying to push and now, when I try to pull from github it's telling me
error: You have not concluded your merge (MERGE_HEAD exists).
hint: Please, commit your changes before merging.
fatal: Exiting because of unfinished merge.

Nor sure how to submit my HW if I can't resolve this tonight.

@kjkaal
Copy link
Author

kjkaal commented Oct 22, 2016

I looked up the error code on github help. I pasted what it said below.
I can't figure out what exactly I need to type into Terminal to get it to work.
I don't know what my branch name is...

Dealing with non-fast-forward errors
Sometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused.

If another person has pushed to the same branch as you, Git won't be able to push your changes:

git push origin master
To https://github.com/USERNAME/REPOSITORY.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/USERNAME/REPOSITORY.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:

git fetch origin

Fetches updates made to an online repository

git merge origin YOUR_BRANCH_NAME

Merges updates made online with your local work

Or, you can simply use git pull to perform both commands at once:

git pull origin YOUR_BRANCH_NAME

Grabs online updates and merges them with your local work

@jennybc
Copy link
Member

jennybc commented Oct 22, 2016

The formatting of your message makes it really hard to read. You can insert text verbatim, such as stuff you've copied from the terminal, by surrounding it with three backticks.

```
blah blah blah
```

which will appear here as:

blah blah blah

While composing a comment, you can always click the "Preview" tab to see what it's going to look like, so you can refine.

Armed with this new knowledge, can you show me what git status shows? You could also repeat some of the above info, in a more readable form.

@kjkaal
Copy link
Author

kjkaal commented Oct 22, 2016

I included a screen shot of what 'github help' says about non-fast-forward errors, which my problem apparently falls under.
I have tried all three suggested commands in Terminal but they all gave me a 'fatal error'.
This is what my terminal says when I open it:

Last login: Fri Oct 21 23:06:19 on ttys000
Katrins-MacBook-Pro:~ kjk$ 

screen shot 2016-10-22 at 11 07 55 am

@samhinshaw
Copy link

I'm so sorry this has happened to you! At the beginning of class Jenny mentioned that git is great until you run into problems... this is that point 😢
The first thing I'd recommend doing is copying your entire repository to another folder somewhere else on your computer so you've got a backup.

Fortunately you don't have to worry about branch names (you only have master):
master

If you're reading help online, it may get confusing if you see references to merging branches. You're not merging branches, but merging local & remote. Fortunately, the process is essentially the same! What you want to do is resolve the merge, and then git will let you push and pull again. This needs to be done locally.

The first thing to do would be to navigate to your git repo in terminal and run git status. If you're not comfortable navigating around your computer with change directory commands, you can also open your R project/repo in Rstudio, and then go to [Tools] -> [Shell], which will open terminal in your repo's working directory.

Then, could you print that error message here, within the backtick formatting Jenny mentioned?

Further reading in this StackExchange thread: git merge --abort

You can also check out the Official Git Documentation 🎉, which is an awful read but will give you the most detail on solving this error.

@jennybc
Copy link
Member

jennybc commented Oct 22, 2016

I suspect you need to do git merge --abort, git pull, git push. But you still haven't shown us the output of git status which would make the situation much more clear. We don't need the screenshots of the github help. We need to see information about the status of your particular repository.

So this is still my question:

Armed with this new knowledge, can you show me what git status shows? You could also repeat some of the above info, in a more readable form.

@kjkaal
Copy link
Author

kjkaal commented Oct 23, 2016

Sorry, I misunderstood which part of my original message you meant.
This is the error message I get when I try to pull from github:

error: You have not concluded your merge (MERGE_HEAD exists).
hint: Please, commit your changes before merging.
fatal: Exiting because of unfinished merge.

This is the error message I get when I try to push to github:

To https://github.com/STAT545-UBC/kaal_katrin-julia.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/STAT545-UBC/kaal_katrin-julia.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.

@kjkaal
Copy link
Author

kjkaal commented Oct 23, 2016

I did what Sam mentioned and ran git status from the shell in RStudio.
This is what it told me:

On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

@kjkaal
Copy link
Author

kjkaal commented Oct 23, 2016

It seems I was able to resolve the problem by following Sam's suggestions.
I am able to push again but now my .Rmd doesn't knit anymore due to a file finding problem :(

@kjkaal kjkaal closed this as completed Oct 24, 2016
@ksedivyhaley
Copy link

Have you tried pulling?

"Integrate the remote changes (e.g. 'git pull ...') before pushing again."

I got a similar error and that fixed it for me. It should integrate with
your new stuff OK but you can backup HW 5 in another folder somewhere just
in case.

On Fri, Oct 21, 2016 at 9:53 PM, Julia notifications@github.com wrote:

I looked up the error code on github help. I pasted what it said below.
I can't figure out what exactly I need to type into Terminal to get it
to work.
I don't know what my branch name is...

Dealing with non-fast-forward errors
Sometimes, Git can't make your change to a remote repository without
losing commits. When this happens, your push is refused.

If another person has pushed to the same branch as you, Git won't be able
to push your changes:

git push origin master
To https://github.com/USERNAME/REPOSITORY.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/USERNAME/
REPOSITORY.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
You can fix this by fetching and merging the changes made on the remote
branch with the changes that you have made locally:

git fetch origin
Fetches updates made to an online repository

git merge origin YOUR_BRANCH_NAME
Merges updates made online with your local work

Or, you can simply use git pull to perform both commands at once:

git pull origin YOUR_BRANCH_NAME
Grabs online updates and merges them with your local work


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#387 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ATA741dRS-jsvs6c1VEpoQN1cq93YGHYks5q2ZblgaJpZM4Kdv4A
.

@khushahal
Copy link

hey i am also facing same problem see here ----

$ git push origin master
To https://github.com/khushahal/khsprivatechat.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/khushahal/khsprivatechat.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.

another command git status
$ git status
On branch master
nothing to commit, working tree clean

i am anable to commit my project to github since 2 days

@FiloSpaTeam
Copy link

@khushahal the same for me. I need to force to push and Github diffs doesn't see changes in Diff view but they are in the code O.o

@mayurpaghdal07
Copy link

@kjkaal write this command
git pull --allowed-unrelated-histories origin master
git push -u origin master

edabruzzo added a commit to edabruzzo/livraria that referenced this issue Mar 20, 2018
@febu1300
Copy link

febu1300 commented May 1, 2018

delete the repository on github create new(don't commit on github), push your files from you localhost.

@cyWisp
Copy link

cyWisp commented May 4, 2018

Had the same problem- mayurpaghdal07's solution worked for me. Thank you!!!

@mambaJun
Copy link

! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:xajhwj/JAVA.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.
Me too,how to do it???

@vincenzocoia
Copy link
Member

@xajhwj Try doing a git pull before pushing.

@mohammedmunna
Copy link

try:

git pull --allow-unrelated-histories origin master
git push -u origin master

@Prasan1
Copy link

Prasan1 commented Oct 13, 2018

@mohammedmunna thanks for those two lines on your comment. That solved my problem.

@rafaewaqarqazi
Copy link

Had same problem...
git pull origin master worked for me 👍

@sriiraj
Copy link

sriiraj commented Jan 14, 2019

try:

git pull --allow-unrelated-histories origin master
git push -u origin master

git pull --allow-unrelated-histories origin master was not working for me plzz help me with this?

@Thilini-Weerasinghe
Copy link

I also having same problrm
git push https://git.... --force
work for me

@umahari
Copy link

umahari commented Feb 2, 2019

blahhhhhhhh

@Jeysoon
Copy link

Jeysoon commented Feb 6, 2019

git push origin master --force worked just fine for me

@rajeshmitsm
Copy link

git pull --allow-unrelated-histories origin master
git push -u origin master

these commands just worked...thanks alot

@OmarFaruk-0x01
Copy link

git pull --allow-unrelated-histories origin master
git push -u origin master

this to line work for mee
tnx a lot.!!!!!!!!!!!!!

@revoldo
Copy link

revoldo commented Apr 12, 2019

git push origin master --force
work for me, thanks

@alexey100196
Copy link

git push origin master --force
Спасибо

@The-Kadweka
Copy link

To https://github.com/AshaAbukar/AFRICAN-BUZZ.git
! [rejected] blue -> blue (non-fast-forward)
error: failed to push some refs to 'https://github.com/AshaAbukar/AFRICAN-BUZZ.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.

how can i attend that

@Meesaan
Copy link

Meesaan commented Jun 25, 2019

Basically, this issue occurs when online and offline repositories are not merged.
If you added a theme or upgrade on github, it means your local repo needs to be upgraded as well. To solve this, I would advise you clone your online repo to your favorite directory-desktop, (git clone https... ). This is a manual solution, works all the time. Now you can add, commit and push.

@annatorsu
Copy link

git push origin master --force
work for me, thanks

worked thanks

@annatorsu
Copy link

git push origin master --force worked just fine for me

@annatorsu
Copy link

worked thanks

@clouddjoe1
Copy link

git push origin master --force

worked just fine for me

@Mann23
Copy link

Mann23 commented Dec 26, 2019

@kjkaal write this command
git pull --allowed-unrelated-histories origin master
git push -u origin master

what does this line do?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests