I am very new to Git; I only recently created a GitHub account.
I\'ve just tried to push my very first repository (a sample project), but I\'m getting the following erro
The following simple steps help me:
First, initialize the repository to work with Git
, so that any file changes are tracked:
git init
Then, check that the remote repository that you want to associate with the alias origin
exists, if not create it in git
first.
$ git ls-remote https://github.com/repo-owner/repo-name.git/
If it exists, associate it with the remote "origin":
git remote add origin https://github.com:/repo-owner/repo-name.git
and check to which URL, the remote "origin" belongs to by using git remote -v
:
$ git remote -v
origin https://github.com:/repo-owner/repo-name.git (fetch)
origin https://github.com:/repo-owner/repo-name.git (push)
Next, verify if your origin is properly aliased as follows:
$ cat ./.git/config
:
[remote "origin"]
url = https://github.com:/repo-owner/repo-name.git
fetch = +refs/heads/*:refs/remotes/origin/*
:
You need to see this section [remote "origin"]
. You can consider to use GitHub Desktop available for both Windows and MacOS, which help me to automatically populate the missing section/s in ~./git/config
file OR you can manually add it, not great, but hey it works!
[Optional]
You might also want to change the origin
alias to make it more intuitive, especially if you are working with multiple origin
:
git remote rename origin mynewalias
or even remove it:
git remote rm origin
Finally, on your first push, if you want master
in that repository to be your default upstream. you may want to add the -u
parameter
git add .
git commit -m 'First commit'
git push -u origin master