DEV Community

Cover image for How to add a remote Github repository to local
Samuel Ochuba
Samuel Ochuba

Posted on

How to add a remote Github repository to local

You might have been given a task to accomplish using github classrooms or created a remote repository on github and you are wondering how to push your local project to the remote repository. In this article i will quickly show you how to accomplish that task. Sit tight.

On the terminal of your ide . you will want to initialize the local directory as a git repository by using this command.

git init -b main
Enter fullscreen mode Exit fullscreen mode

This command converts your local repository into a git repository. The next thing you would want to do is add the files you have in your local repository into your git repository by committing them. Before committing the files you would first have to add them . The command for adding is below

git add .
Enter fullscreen mode Exit fullscreen mode

After adding the files you then commit it to the local git repository by using the command:

git commit -m "First commit"
Enter fullscreen mode Exit fullscreen mode

First commit represents the commit message. it is usually a short title that is an overview of what you have done. This local commit also prepares the files to be pushed to a remote repository.

At the top of your github online repository setup page you would see the repository url . either HTTPS or ssh. depending on your organization's requirements

Alt Text

You would need to add the url you have copied to your local github repository by using the below command.

git remote add origin  <REMOTE_URL>
Enter fullscreen mode Exit fullscreen mode

Then verify the remote url

git remote -v
Enter fullscreen mode Exit fullscreen mode

After adding the url to the local github repo. You can then push your changes to your online repo by using the below command

 git push -u origin main
Enter fullscreen mode Exit fullscreen mode

With main being the name of the branch online you are pushing your local changes to

Thank you very much and i hope this article helps you with your first steps in github. I am always free to answer questions and help. you can check my profile out on twitter
@rake_code

Top comments (0)