Cheatsheet of Git Basics

Rakshit KoyaniRakshit Koyani
2 min read

What is Git?

Git is an open-source distributed VCS (version control system) that is used nowadays by every single programmer and also in tech companies.

Difference between Git and Github

Some of you also heard about GitHub which is used for hosting our local repositories and also controls versions and changes like Git. Github is totally dependent on Git but Git can exist without Github.


Let's see some basic commands used in Git.

1. Setup and initialize git repository

git config --global user.name “[firstname lastname]”
git config --global user.email “[email]”

This will configure user information across all local repositories. to see all user details we type below commad.

git config --list

Then initialize an existing directory as a Git repository by the below command.

git init

This will create an empty Git repository or reinitialize an existing one.

2. Staging and working on current changes

git status

This is most used command used in git. To check the modified files in working directory, staged for your next commit

git add [filename]

This command is used to add a particular file or files to the staging area. use git add . for all files.

rm [filename]

Remove files from the working tree and from the index

git diff

this will show the files changed but not staged yet.

git diff --staged

It will show the files which is staged but not commited.

git commit -m “[ message]”

This will commit changes of files and snapshot a staged content.

3. Branching and Merge

git branch

It will show the current branch with "*" symbol.

git branch [branch name]

It will create a new branch. First, we need to checkout before creating a new branch.

git checkout

It will switch to another branch and checkout from current working directory.

git log

It will show the commit history.

git merge [branch name]

It merges(join) two or more development histories together. for ex. merge different child branches into master for final production.

git clone [url of remote repository ]

It will clone the remote repository to our locale machine

These are basic Git commands necessary to start using Git. You can refer git-scm site for other commands which are used for advance operation.

0
Subscribe to my newsletter

Read articles from Rakshit Koyani directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rakshit Koyani
Rakshit Koyani