DEV Community

Cover image for Basic Git commands that programmer must know
sandeep kumar
sandeep kumar

Posted on

Basic Git commands that programmer must know

Few commands are using in Git bash (window), and a programmer must know about it, such as ‘$git init, $git touch, $git mkdir, and many more that will be discussed in this blog. If you are a Windows or Mac IOS0 user, you need to download the ‘git bash’ from google, and after installing, you can use it on your local laptop or PC (personal computer) to manage your local files. You don’t need internet for ‘Git Bash’ because it would run in your local machine without the internet.
Screenshot (186)

Downloading link here-Git -https://git-scm.com/downloads

When you download the Git Bash on your laptop or PC, you have to run a command to familiar git with you by your’s name and e-mail ID because when you start work on ‘GitHub’, at that time, it will use your name and e-mail ID as an ‘Author’. You need to run a few commands on your Git to save your’ name and e-mail’.

git config –global user.name ‘adam smith’ {Click on Enter}
git config –global user.email ‘adam1234654@gmail.com’ {Click on Enter}
Screenshot (187)_LI

After doing this, it will show you like the above pic. You can check that Git saves your name and e-mail or not by using the same command, but you do not need to write your complete name and e-mail at this time. For this, commands that you can use;

git config –global user.name {Click on Enter}
git config –global user.email {Click on Enter}

Once you run the command into your ‘Git Bash’, it will show your name and e-mail just below the command that you run like this;
Screenshot (188)_LI

Now you are ready to work on Git Bash because it saved your name and e-mail. The main reason for keeping your details is that when you work with multiple people on the same project, it will saves every group member’s work with a name. Any group member can check the particular member work by seeing the “Author” name.

There are few rules you need to keep in your mind that git does not work directly in your local machine (laptop/ PC). You have to create a “repository” where git will save all your works. Under repository, you have to make different branches that help you work on multiple files under a common repository. This blog leads you from start to end without any problem, and you need to practice side-by-side.

Some Basics commands of Git Bash;

start . {click on Enter} #It will open the file manager in Window.

cd {click on Enter} #Current Directory

cd .. {click on Enter} # For one step back from the Current Directory

git init {Click on Enter} # it will create an empty “repository.’

touch ‘File name’ {Click on Enter} # You can create a file using this command line

mkdir ‘folder name’ {Click on Enter} # You can create a folder where all your files save under it

git branch ‘branch name’ {click on Enter} # It will create new branch

git add ‘file name’ {Click on Enter} #This command will bring your file to the staging area

git commit -m ‘commit msg’ {Click on Enter} #This command will bring your file to the local repository

rm ‘file name’ {click on Enter} #It is used for deleting file

rm -rf ‘folder name’ {Click on Enter} # It is used for deleting folder

git status {Click on Enter} # It is used for getting branch status

git branch -d ‘branch name’ {Click on Enter} #It is used for deleting branch

You can use this in your local machine initially and make some changes as you need. At the initial stage, you need to create an ’empty repository’ where you will save your work and push on GitHub (hosting plateform). There is a link is provided you to understand more about repository What is a GIT Repository? – GeeksforGeeks

Create a new local repository:

We need to create an empty local repository by using the “$ git init ” command. Once you run the command, it will reply like “Initialized empty Git repository in C:/Users/sande/.git/”, and now you are ready to work under creating the repository. Secondly, we need to create branches that help to save files (works) under the repository. We will run the command “$ git branch ‘branch name’ ” that create the new branches under the repository. The main function of branches is to track the files and bring them to a staging area where they are ready to be committed. Now we will create new files, “touch ‘file name'” and do some work. Before going further, you need to understand the below diagram.

git staging image

https://miro.medium.com/max/2878/1*w1VuGNH-cT3fc4KPPB_Q9Q.png

In this diagram, “git add and git commit” commands are used to save files under the Git repository. We will use the “$ git add” to bring our works to the staging area. Staging area like git starts to keep its eye on files; if you make some changes in that files, it will show you status about the files. When you run the “git commit” command, it will send your files under the Git repository.
Screenshot (189)

The above picture shows you the git commands, and you can run them on your local machine. Git is the most popular version control system used by the programmer, companies, and developers. Basically, It saves your time and keeps your content safe and secure without any modification and risk.

Thanks

Top comments (0)