-1

I am trying to push my code into my private github repository using my terminal but it is not working.

I tried using the git push command for trying to add files into the repository.

git remote add origin <url for the github repo>

Then I used the following code to push it into the repository

git push -u origin master
To https://github.com/arunkumarindosyd1994/git-test.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/arunkumarindosyd1994/git-test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first 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.

How do I get help in this scenario?

  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+remote+contains+work+that+you+do – phd May 17 '19 at 12:18

2 Answers2

2
  1. Do a git pull to grab the latest changes from the server.
  2. Resolve any merge conflicts.
  3. Commit any merge conflict changes.
  4. git push your changes back up.
NRitH
  • 13,441
  • 4
  • 41
  • 44
1

If you carefully look into the error message, it is giving you this hint :

not have locally. This is usually caused by another repository pushing
to the same ref. You may want to first integrate the remote changes
(e.g., 'git pull ...') before pushing again." 

That means your local repository is outdated and there are some new changes in remote repository which are not present in local.

You first need to make your local repository upto date by either : git fetch or git pull

git pull = git fetch and merge. so if you are doing git fetch, you have to merge your changes explicitly. But git fetch is highly recommended because it is safer than git pull.

After that you have to resolve merge conflict( if any) and commit your changes.

And now you can push your changes to git.

user
  • 867
  • 9
  • 21