Often, when we set up version control initial files for a project, we tend to log onto the Github website to create our repositories, clone, and push our projects. While this method works, it can be argued that it is not as efficient. We can manage our GitHub repositories, from creating the repo to maintaining the different versions, right from our terminal. In this article, we will go through the process of achieving this.
I will be attempting to create a repository for the Nextjs practice project I am currently working on and then push the files from my local machine to the the repository, and I will be doing all of it from my terminal.
All you need to acheive this is a basic knowledge of the command line interface, and of course a github account.
**
Step 1 - Install Github CLI
**
For Mac
brew install gh
For Linux (Ubuntu)
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
sudo apt-add-repository https://cli.github.com/packages
sudo apt update
sudo apt install gh
**
Step 2 - Authenticate with Github
**
Upon installation completion, you will need to authenticate with Github. Run the following command.
gh auth login
This will take you through series of authentication processes. You can choose to authenticate using a web browser or by pasting an authentication token. For any option you choose, just follow the prompts and you will be all set.
I will be using the web browser (for the last time).
To verify authentication status, run...
gh auth status
**
Step 3 - Create Repo
**
It's time to create the repo for our project. Do this using the command
gh repo create <repository-name> --public
Be sure to replace repository name with your choice repository name.
The public flag is usually required. It helps github decide if to make your repo public or private. Use --private
id you want otherwise. There are other flags that you can use. Go through the documentaion to learn more about your options.
**
Step 3 - Clone the repository and add files locally
**
At this point, your repository is up on your github account. It can be accessed via the github url from the command output. We will have to clone the repository, and add our project files from our local machine. To do this, change directory to where you want to have your cloned repo and run the command.
gh repo clone <repository-url>
As usual, replace the repository-url with your repo url.
After cloning, if you had already started working locally ads in my case, move your project files to the cloned repo, if not, you can start working from your cloned repo.
**
Step 4 - Pushing files to github
**
Now we will have to push our initial project files to our remote github repository. But before then, let us quickly inspect our repo on github to be sure it was created and that it is empty.
Great!
Now run the follwoing commands to get your project files in.
git add .
git commit -m "<commit message>"
git push
If everything is okay and you have a successful push, your project files should be up on github and in the repository that you created earlier.
Access github via the browser to confirm you had a successful push.
**
Conclusion
**
At first, the process of setting up your working environment for seamless repository management using just the command line may seem intimidating. However, once you give it a try, you will realize that it is actually quite easy and straightforward. As you become more comfortable at using your terminal, you will begin to appreciate the efficiency of working mostly from the command line and the conveneince it gives your workflow.
There are many other powerful features and commands that the Github CLI offers. These features help us manage or repositories more efficiently. You can check a few other features that may fit your repository management needs on the Github CLI Documentation.
Happy Commits!
Top comments (0)