The following steps work for me:
Init
First, initialize the repository to work with Git
, so that any file changes are tracked:
git init
Create alias origin
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 alias "origin":
git remote add origin https://github.com:/repo-owner/repo-name.git
and check to which URL, the remote alias "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)
Verify alias origin
Next, verify if your alias 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 must 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!
Pull any contents from remote main branch
$ git pull origin main
This will pull any contents you have on the repository you just aliased to origin
to the local repository, including .gitignore
, creating the branch main
in the process.
Check main branch
$ git branch
* main
This will show you that main
branch has been created and you are now on it(as indicated by the * ).
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 my-super-git-repo
Finally
git add .
git status //If you want to check what's going to be committed
git commit -m 'First commit' //-m is for message
git push origin main
You will see a bunch of lines as follows:
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 8 threads
Compressing objects: 100% (13/13), done.
Writing objects: 100% (21/21), 4.29 KiB | 292.00 KiB/s, done.
Total 21 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), done.
To https://github.com/repo-owner/repo-name.git
948279c..1f3b0b8 main -> main