N. Cross N. Cross - 1 year ago 67
Git Question

How to push your changes into a forked repros on Github?

I'm gonna start with some detailed background information:

Usually for our lectures we git clone our teachers repros into one of the schools servers.
We then make our changes on the files, commit them and push them from PuTTy.

For our homework we fork the teachers reprositry, git clone them into the server and the same stuff happens again.

Which brings me to my specific problem: Namely, since it was already cloned I saw no need to copy the files over again so I went ahead with my changes, git add ., git commit -m "comment" but when it came to pushing the changes into Github, it pops up an error. This is all really weird because I've already pushed my commits into my forked reprositry yet this time it doesn't seem to work for some reason.

Error message:

To https://my_account@github.com/my_account/homework.git
! [rejected] master -> master (non-fast-forward)

error: failed to push some refs to 'https://my_account@github.com/my_account/homework.git'

To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.

See the 'Note about
fast-forwards' section of 'git push --help' for details.

I'm a total beginner when it comes to git so I apologize in advance if this is a stupid or unclear question.

Answer Source

You should do this:

git pull origin your_branch

or (the above command equal two below steps):

git fetch origin your_branch
git merge your_branch
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download