简体   繁体   中英

Git fails to push a local .md file to remote repo

I'm a newbie in Bioinformatics and currently signed up with a data science online course where it has asked the following tasks to be done as an assessment. I'm running git on MacOSX Mavericks.

1.Create a text file called HelloWorld.md

2.Add the line "## This is a markdown file" to the document

3.Push the document to the datasciencecoursera repo you created on Github

4.Submit the link to the HelloWorld.md file on your Github repo.

I have so far managed to set the remote repo and also created the helloworld.md using a text editor and copy the file into the datasciencecoursera. But when I try to push everything on that folder into the remote repo, following error is displayed.

Harindras-MacBook-Pro:datasciencecoursera Harindra$ git push
To https://github.com/HarindraDS/datasciencecoursera.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/HarindraDS/datasciencecoursera.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.

Can someone suggests me how to solve this error. Please note I'm not a programmer by any means and therefore any help you could offer would gratefully be received.

Your only problem is that since last time you update your project somebody has modified it.

As example imagine that when you clone the remote project, it's version id was 1 so your local copy version id was 1 too; since that time somebody has pushed some changes so current remote project version id has been increased and is 2 now.

When you try to push your changes git detects that you have a different version id than remote (so your project is not updated) and rejects your pushing; to solve it you must fetch newest changes and pull them into your local repository (what is called a merge)

Once merged your local repository will be upgraded to the same version than remote (what means that your repository is updated with remote content) and git will allow you to push your changes

git pull --rebase 
git push origin master

git pull --rebase will apply your changes after those already made to that branch. This video literally goes over your exact issue and solves it using git pull --rebase https://youtu.be/IhkvMPE9Jxs?t=10m36s

Yes, you need to update what is already in the repo. Then it should work. See below.

 ~/datasciencecoursera (master)
$ git pull https://github.com/scarebaer/datasciencecoursera.git
From https://github.com/scarebaer/datasciencecoursera
 * branch            HEAD       -> FETCH_HEAD
Already up-to-date.

~/datasciencecoursera (master)
$ ls
HelloWorld.md  README.md

~/datasciencecoursera (master)
$ git push origin master

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM