Skip to main content

Command Palette

Search for a command to run...

Developer's guide to GIT.

Published
3 min read
Developer's guide to GIT.
S

Learning to code.

What is GIT?

GIT is a open-source version control system that enables you to store code, track changes you have made to the code, merge code changes and recover earlier versions of code when needed.

What is Github?

Github is a hosting website that hosts Git repositories. There are also other websites which hosts git repositories like Gitlab etc. but Github is the commonly used one.

Well, before starting with Git commands you must know a few important terms.

Working Tree

The working tree or working directory contains the files that you are currently working on.

Staging Area or Index

This area contains all the added files that contain new or modified code which is ready to be committed. All modified or changed files are first pushed to the staging area.

Repository

Git repository contains all files of the project. It tracks changes done to your project i.e it holds all commits.

Git commands

There are a lot of Git commands but here is a cheat sheet of most commonly used ones:

1.git config

git config --global user.name "[firstname lastname]"
git config --global user.email "[email address]"

Used to configure an username and email address respectively to be used with all your commits.

2.git init

git init [repository name]

Used to start a new repository

3.git status

git status

It shows the status of your git means lists down all files that is being committed.

4.git add

git add [file]

Adds a file to the staging area or index.

git add *

Adds one or more files to the staging area.

5.git diff

git diff

This command shows files that are not staged yet.

6.git commit

git commit -m "[commit message]"

Records a file permanently in the version history.

7. git reset

git reset [file]

This command unstages the file while retaining the changes in working tree.

8. git clone

git clone [url]

Used to obtain a repository from an existing URL.

9. git branch

git branch

It lists all your branches. A * appears next to the current branch.

git branch [branch name]

It creates a new branch at new commit.

10. git checkout

git checkout [branch name]

This command is used to switch one branch to another branch.

11. git merge

git merge [branch name]

This command merges the specified branch’s history into the current branch.

12. git log

git log

This command show all commits in the current branch’s history.


There are many other git commands but these are the most needed ones. To know more refer to the Git website. Hope this article will help you understand git commands easily. Happy coding!

M

Nicely articulated

S

Thanks!