Reputation: 1994
I have just created a new project and added some files there. Then I have created a new GitHub repository (public).
Now I want to push my local Git project to the remote GitHub.
So I do that:
git init
git add .
git commit -m "First commit"
Then:
git remote add https://github.com/user/project.git
git remote -v
# origin https://github.com/user/project (fetch)
# origin https://github.com/user/project (push)
Then I am trying to push my new project items:
git push
# fatal: The current branch master has no upstream branch.
# To push the current branch and set the remote as upstream, use
# git push --set-upstream origin master
So I am doing as said:
git push --set-upstream origin master
And get back:
# To https://github.com/user/project
# ! [rejected] master -> master (non-fast-forward)
# error: failed to push some refs to 'https://github.com/user/project'
# 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.
So I keep following their instructions:
git pull
And I get:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
And continue doing what they write:
git pull origin master
And get back:
From https://github.com/user/project
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
I have managed this to be working only by using
git clone https://github.com/user/project
But I do not think that this is the right way of working, is it?
Hope for some tips. Thanks.
Upvotes: 0
Views: 466
Reputation: 84529
Personally I simply proceed as follows. I don't run git
on my computer to create a project:
create the repo on Github
clone it
move the obtained .git
folder (and optionally the README
file and the .gitignore
file) to the working folder
Then you're ready for add
, commit
, push
.
Upvotes: 1
Reputation: 79
You should run this command,
git remote add origin https://github.com/user/project.git
not
git remote add https://github.com/user/project.git
Upvotes: 1