Reputation: 7520
I am studying git now and I have a problem in pushing my existing files in the new repository I created in Github.
Here's what i did:
- git init
- git add .
- git commit -m "This is the base code for the project"
https://github.com/myname/my_projects.git
- git remote add origin https://github.com/myname/my_projects.git
- git push origin master
Then after doing the push I have this error:
λ git push origin master
Username for 'https://github.com': myname
Password for 'https://myname@github.com':
To https://github.com/myname/my_projects.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/myname/my_projects.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.
Can you help me with this?
Upvotes: 1
Views: 140
Reputation: 3818
You probably initialized the repo on Github with a README file. If so, you can do as the earlier answer suggested, or you can pull first with:
git pull origin master
Your branch is not up to date since the remote has a README file and you don't have this file locally. After you pull, you would have to commit again, but what this would do is tell Git that your local branch to be up to date with the remote branch.
After this point you can just do push as usual:
git push origin master
Upvotes: 2
Reputation: 60163
git push --force origin master
if you're sure you want to overwrite what's on your github remote with what you have locally.
Upvotes: 3