Join our community and get latest updates!

Saturday, February 6, 2021

How to Manage a Git Repository in Linux Command Line

Hello friends, In this section we would learn how to manage Git repository using command line, and further how to handle the repository with various commands. I am writing this article to ease what you would find in other sources.

I don't want to bore you with an introduction to Git, i assume that you already know what Git is and what its used for. Its a very useful tool for programmers and developers
Table of Contents

Steps to Create a Git Repository

Create an empty repository in your GitHub account. You can leave readme and license which can be added later.

Suppose you have a project folder DEMO in your linux PC, Open the command line inside the folder DEMO and follow the below commands.

Initialise your local folder as Git repo

git init -b main

Add the files in your new local repository

git add .

Commit the files 

git commit -m "Initial Commit"

Copy the repo URL

It would be something like this https://github.com/user/demo.git

Set the Git repo

git remote add origin https://github.com/user/demo.git

Verifies the Git repo

git remote -v

Push local repo to Git

git push origin master

Set remote repo to local repo

git remote add origin https://github.com/user/repo.git

Current Branch Info

git branch

List all branches in repo

git branch -a

Switch to another repo

git checkout branch

Conclusion

I hope that this article on "How to Manage a Git Repository in Linux Command Line" helped you to understand better about Git commands. If you think something is missing in our article please let us know.

You can freely comment on your doubts and queries below. If you liked this article, then please share this with your friends. You can also find us on Twitter, Facebook, YouTube, and Instagram.

I'm an Electronics Engineer with years of experience in Blogging and DIY Projects. I like to make new gadgets and write contents related to technology and Blogging.

Disqus Comments
Disclaimer : Muhammed Fasil K is a participant in the Amazon Services LLC Associates Program, an affiliate program to earn commission by advertising and linking sites to Amazon products.