How to connect my local project to an existing remote Github repository?


Everywhere I look, all I see is the standard:

git add remote origin <url>

followed by: add/commit/push

I do not want to add, commit and push anything. I just want to link my remote repository, and then be able to change branches, so I can create a new branch inside my repository, and then push stuff in it. Currently, when I do the git add remote origin <url>, and then do git branch, I see nothing. git branch -r also does not nothing. Why? Where are all my branches? If I do git checkout master, it doesn’t work.

What I want is to do the same thing as cloning a repo, but instead of cloning it, I want to link it to my project. I do not want to commit or push anything into my master branch.

How do I connect it?


The reason you do not see the branches of your remote repository in you local repository is that you missed the call to git fetch.

Do a

git add remote origin <url>
git fetch origin
git branch -r

and you will see the remote branches in you local repository. You can then checkout to one of them by running

git checkout -b <branch name>

After that it is the usual add/commit/push workflow again.

Answered By – SebDieBln

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published