Photo by Glenn Carstens-Peters on Unsplash
How to Connect a local repository to a Github Repository
(In 6 Easy Steps)
Hey reader,
Today, you will learn how to connect your local repository (A repository on your PC) to a remote repository (GitHub). This article is suitable for readers with no experience in Github.
Before going deeper into this, It's necessary to know what Github is. Github is an online hosting service for software development and version control using Git. In much simpler terms, Github provides a distributed control of Git plus access control, bug tracking, software feature requests, task management, continuous integration, and wikis for every project.
Now, that we have a basic understanding of Github, let's dive right into it.
1. Create A Repository on Github
Simply login into your Github account and click the new button to create a new repo. For this article's sake, we will create a new repository using only default settings. For readers who do not have an account with Github, click on the link Create Gitbub Account to create your account.
You can name your repository anything you like. I have named mine #PYTHON_CODE
2. Change the directory to your local project
Next, we have to cd
into our local project via our git bash terminal. In our case, the file we want to Connect to Github exists in the following path:
C:/Users/User/documents/python/index.py.
NOTE: you are to cd
into the folder containing the file you wish to push to Github and not into the file itself. In our case, the folder path is:
C:/Users/User/documents/python/
Notice the absence of the index.py
file.
Also, ensure that you activate your virtual environment if you have one.
3. Initialize an empty repository in your project.
Ensure you are in the right file path before initializing an empty repository. To confirm your current path, run pwd
in your terminal.
Once you've confirmed the file path is correct, run the git init
command in your terminal. You should get a response similar to this:
4. Add the file to the staging area
Next, run the git add -A
command. The essence of this command is to add all files present in our repository to the remote repository. In our case, we have only one file which is our main.py
file.
5. Commit the file
Next, run the git commit -m
command. The -m extension stands for "message" The message is usually a brief description the user includes. It helps you identify the change made.
6. Pushing to the remote repository
The previous steps were preparatory steps to this step. To push our files to the remote repository, run the following command:
git remote add origin https://github.com/prosper-20/PROJECT.git
Next, run the command below:
git push -u origin master
To confirm that the code was pushed successfully, simply run git remove -v
in your terminal.
That's all folks. I hope you've enjoyed reading this article. Kindly share this article with your friends, family, and fellow developers.