DEV Community

Cover image for All you need to know about Git ๐Ÿš€
Viraj Nimbalkar
Viraj Nimbalkar

Posted on • Updated on

All you need to know about Git ๐Ÿš€

What is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git was created by Linus Torvalds in 2005 to develop Linux Kernel and it is most widely used modern version control system in the world today.

What is Version Control System(VCS)?

Version control systems are a category of software tools that help a software team manage changes to source code over time.
Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code.


Following are some essential git commands you must know as a beginner:

1] git version

This command helps you to check your current version of git.
Latest version of git is 2.28.0.

Command: git --version
Enter fullscreen mode Exit fullscreen mode

2] git config

git config โ€“global user.name โ€œ[name]โ€
git config โ€“global user.email โ€œ[email address]โ€
This command sets the author name and email address respectively to be used with your commits.

Command: git config --global user.name "Viraj Nimbalkar"
Command: git config --global user.email "virajnimbalkar55@gmail.com"
Enter fullscreen mode Exit fullscreen mode

3] git config list

This command helps you to check your configuration settings.

Command: git config --list
Enter fullscreen mode Exit fullscreen mode

4] git init

This command is used to start a new repository.

Command: git init /viraj/files/git-basics
Enter fullscreen mode Exit fullscreen mode

The folder git-basics will be initialized as a git repository here.


5] git clone

git clone [Repository Link]
This command is used to obtain a repository from an existing URL.

Command: git clone https://github.com/Viraaaj/Weather-PWA.git
Enter fullscreen mode Exit fullscreen mode

6] git add

This command adds a file to the staging area.

Command: git add [filename]  //adds a file to the staging area.
Command: git add .  //adds one or more files to the staging area.
Enter fullscreen mode Exit fullscreen mode

7] git commit

This command records or snapshots the file permanently in the version history.

Command: git commit -m โ€œ[type Commit message here!]โ€
Enter fullscreen mode Exit fullscreen mode

8] git status

This command lists all the files that have to be committed.

Command: git status
Enter fullscreen mode Exit fullscreen mode

9] git log

Following command is used to list the version history for the current branch.

Command: git log
Enter fullscreen mode Exit fullscreen mode

Following command helps to view commit history by displaying the first seven characters of the SHA-1 hash and commit message of the commits on the current branch.

Command: git log --oneline
Enter fullscreen mode Exit fullscreen mode

10] git branch

Following command is used to list all the local branches in the current repository.

Command: git branch
Enter fullscreen mode Exit fullscreen mode

Following command is used to create a new branch.

Command: git branch [branch name]
Enter fullscreen mode Exit fullscreen mode

Following command is used to delete the feature branch.

Command: git branch -d [branch name]
Enter fullscreen mode Exit fullscreen mode

11] git checkout

Following command is used to switch from one branch to another.

Command: git checkout [branch name]
Enter fullscreen mode Exit fullscreen mode

Following command creates a new branch and also switches to it.

Command: git checkout -b [branch name]
Enter fullscreen mode Exit fullscreen mode

12] git merge

This command merges the specified branchโ€™s history into the current branch.

Command: git merge [branch name]
Enter fullscreen mode Exit fullscreen mode

13] git remote

git remote add [variable name] [Remote Server Link]
This command is used to connect your local repository to the remote server.

Command: git remote add origin https://github.com/Viraaaj/Weather-PWA.git
Enter fullscreen mode Exit fullscreen mode

14] git push

git push [variable name] master
This command sends the committed changes of master branch to your remote repository.

Command: git push origin master
Enter fullscreen mode Exit fullscreen mode

git push [variable name] [branch]
This command sends the branch commits to your remote repository.

Command: git push origin master
Enter fullscreen mode Exit fullscreen mode

git push โ€“all [variable name]
This command pushes all branches to your remote repository.

Command: git push --all origin
Enter fullscreen mode Exit fullscreen mode

git push [variable name] :[branch name]
This command deletes a branch on your remote repository.

Command: git push origin : branch_1
Enter fullscreen mode Exit fullscreen mode

15] git pull

git pull [Repository Link]
This command fetches and merges changes on the remote server to your working directory.

Command: git pull https://github.com/Viraaaj/Weather-PWA.git
Enter fullscreen mode Exit fullscreen mode

Top comments (0)