Git Commands cheat sheet

Git is a command-line tool, the following commands are the most used:

Related Articles:

Git configuration commands

  • git config is used to configure and set up Git for the first time:
 $ git config

 $ git config --global user.name "your name"
 
 $ git config --global user.email "your-email"
 
 $ git config --list

Create and initialize a Git Repository

 $ git init

 $ git status
 
 $ git add file_name.js

 $ git add file_name1.js  file_name2.txt  file_name3.js

 $ git add .

 $ git add --all

 $ git add -A

 $ git rm --cached file_name.js

 $ git reset file_name.js

Git commit commands

  • The command git commit is an important Git command. To use this command, you should have at least added one file to the staging area.
 $ git commit -m "Add your message here"

 $ git commit -a -m "Your message here"

 $ git reset --soft HEAD^

 $ git add file_name.html

 $ git commit --amend -m "Add your message here"

Git branch commands

Git branch commands are very helpful specially when you are working on a project with other developers.

 $ git branch

 $ git branch branch_name

 $ git checkout brunch_name

 $ git merge your_branch_name

 $ git branch -d branch_name 

Git Push and Pull commands

Git push and git pull are both Git remote commands.

 $ git push -u origin branch_name
 
 $ git push 
 
 $ git pull

Git help commands

 $  git help

 $  git help <theCommandName>

Git remote commands

 $ git remote add origin https://github.com/username/repository-name.git

 $  git remote -v

 $ git clone https://github.com/dusername/repository-name.git

 $ git clone  -branch  branch_name  https://github.com/username/repository-name.git

 $ git remote add upstream https://github.com/TheOwnerUsername/original-repository-name.git

 $ git clone --bare https://github.com/username/original-repository-name.git

 $ git push --mirror https://github.com/username/new-repository-name.git

 $ rm -rf repository-name.git

You might also like:

3 easy steps to create React application.

How to create React Web App with a Node.js API Backend.

How to make Axios Requests in React to a nodejs API.

How to use React Hooks in Functional Components.

5 Steps to Set up React Development Environment.

How to clone GitHub repository and branches.

What are Component Lifecycle Methods in React.

How to open Visual Studio code from Command Line.

How to deploy React app to Heroku.

Complete Guide on how to use Git and GitHub.

How to get Request Origin in Express.js?

How to get the Request Host in express.js?

How to Get Current Date and Time in JavaScript.

How to add Custom Error Handler Middleware to your Node.js/Express API.

Complete JWT Authentication and Authorization System for MySQL/Node.js API.

How to Build a Complete API for User Login and Authentication using MySQL and Node.js.

Node.js + MySQL : Add Forgot/Reset Password to Login-Authentication System.

Nodemailer + Gmail: How to Send Emails from Node.js API using Gmail.

How to store Session in MySQL Database using express-mysql-session.

How to interact with MySQL database using async/await promises in node.js ?

How to use Sequelize async/await to interact with MySQL database in Node.js.

MANY-TO-MANY Association in MYSQL Database using Sequelize async/await with Node.js.

ONE-TO-ONE Association in MYSQL Database using Sequelize async/await with Node.js

ONE-TO-ONE Association in MYSQL Database using Sequelize async/await with Node.js.

How to add Routes to insert data into MySQL database-related tables in Node.js API?

Example How to use initialize() Function in Node.js/Express API .

Why is Connection Pooling better than Single Connection?.

How to create MySQL database using node.js.

Translate »