DEV Community

aCompiler
aCompiler

Posted on

Basic Git Commands

If you want to use git to it's full potential, you must know about Git commands.

Why?

Can you drive a car if it's does not have any fuel ?
No

Fuel is an essential element for car.

Similarly, Git commands are essentials. You have to master this skill at some stage, especially if you are a software developer.

Git is popular,Microsoft uses git. So there is no doubt why its important.

And today I will show you five basic git commands which will help you to a kick start your git journey.

git --version

git add

git add -A

git status

git commit -m β€œyour commit message”

So lets dive in more details

git --version

You can check your current version if git with git --version command

Alt Check git version control with command line

With this you can make sure that you are not using the old version.

git add

Git add command will use to add new files to the staging area.

With the gid add command you can add single file to the staging area

git add -A

And with git add -A command you can add multiple files into the staging area.

Here -A is a switch or option and A stands for all.

Also you can use git add . command, to add all files into the git staging area.

git status

It is one of the important command. You can check your current branch and list of files which are required to commit

git commit -m β€œyour commit message”

Alt git commit

Once you are ready to commit your changes it's time to commit.

Here -m option stand for your message. You want to commit with some message so you can refer that later.

Also in case if you want yo update your last commit message you can use

git commit --amend -m "your updated commit message"

So basically, git commit will add your changes to git repository from staging.

What is git staging area

Pictures speak louder than words.

Here is the one

Alt git staging area

Basically staging is a middle step between your working directory and repository.

I have a complete list and a bonus cheat sheet for you to download here.

Hope it's easy for your to understand these git commands.

Let me know in by comment about your git journey.

Top comments (7)

Collapse
 
vikramvee profile image
Vikram Chaudhary

If git commit adds changes to the git repository then what is the use of git push

Collapse
 
acompiler profile image
aCompiler

Nice Question Vikram.

If you are working in team then you need to share your code with them and you need remote repository.

As Heinek answer - git commit only for local repository and git push for remote repository.

Collapse
 
vikramvee profile image
Vikram Chaudhary

That was helpful.

Collapse
 
harveyhalwin profile image
Heinek Halwin

Git commit adds the changes to the local git repository, when you use git push, it pushes the code from your local to the remote(GitHub, bitbucket etc)

Collapse
 
acompiler profile image
aCompiler

Nice !

Collapse
 
svijaykoushik profile image
Vijay Koushik, S. πŸ‘¨πŸ½β€πŸ’»

Great information about the basics

Collapse
 
acompiler profile image
aCompiler

Thank you Vijay