Git Commands Every Developer Should Know

For initialize git in a folder

git init

For set a user name and email as user globally for all repository

git config — global user.name “xyz”

git config — global email ”abc@gmail.com”

For set a user name and email as user for individual repository

git config user.name “xyz”

git config email”abc@gmail.com”

To see the user name and email and other configure information's

git config — list

To see the the current status of your project or folder or working directory

git status

To stage a single file from working directory to staging area

git add cold.txt

To stage all file from working directory to staging area

git add — all

git add .

To commit

git commit -m “two file added”

To see all commit details

git log

To see all commit in short

git log — oneline

To see a single commit status

git checkout (commit number)

To create a new branch

git checkout -b <new-branch-name>

Switch to master branch from current branch

git checkout master

To see difference from last stage to new stage

git diff

To see the specific commit status

git show (commit number)

To see difference between two commit

git diff old commit number new commit number

To see difference between local repository & working directory

git diff — staged

To remove or delete a file from local repository but it will track

git rm file_name

To remove or delete a file from staging area it will not track any more

git reset HEAD file_name

Push anything to current branch

git push

Push to any branch

git push branch-name

Clone a repo

git clone (clone_link)

git clone (clone_link) new _name

For fetching branches

git fetch

git fetch -all

Pull data from current branch

git pull

pull from any branch

git pull branch-name

To see the all branch list

git branch

Switch to any branch from current branch

git checkout branch-name

To create a new branch

git checkout -b branch-name

To merge current branch to master

git merge branch-name

To Delete a branch

git branch -D branch_name

To Delete or hide or remove last action/status from a file

git stash

To get back before stashing status

git stash pop

git stash apply

To get all stash list

git stash list

To get a single stash list

git stash pop (stash_sl_number ex:stash@{0})

To check what will happen if you run

git clean -f

git clean -f -n

To delete a unstaged or untacked file

git clean -f

To create a gitignore file

touch .gitignore

--

--

--

I’m a developer, educator, writer| Software Engineer | Backend focused | PHP JS

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Teaching a machine to convert wireframes into code

Modern C++ in Advent of Code: Day23

Thread-safe Code Through TDD

Postman: Sending the first request

Instant VM Recovery from Backup

Weeknotes s02e12

The Cypher Query Language — Best Practices

Blog 5: Week of Feb 14 — Feb 20

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mohasin Hossain

Mohasin Hossain

I’m a developer, educator, writer| Software Engineer | Backend focused | PHP JS

More from Medium

Best practices for CodeIgniter API development — The Right Software

Introduction: Getting started “REST API” with Lumen

Using Minio to work with S3 buckets locally

Using Minio to work with S3 buckets locally