DEV Community

Cover image for Git commands cheat sheet 2022

Posted on

Git commands cheat sheet 2022

Do you want to learn some basic GIT commands? You’ve come to the right place. Read our simple cheat sheet that you can use for daily reference.

What is git cheat sheet?

The git cheat sheet is a concise, easy-to-read document for quickly learning how to use some of the most popular and useful commands in the Git environment. It’s designed for beginners who are new to Git and have little or no prior experience with it.

Most Common GIT Commands

A git command cheat sheet is a document that lists the most commonly used commands and their corresponding syntax.
The following is a list of git commands with syntax:

-git add -A
-git commit -m “commit message”
-git push origin master
-git pull origin master
-git clone {URL of git repository}

Basic Commands of Git

Here are some basic GIT commands you need to know:

#01: How to setup git config

git config:- can be used to set user-specific configuration values like username, email, file format, and so on.

  • set a username that is identifiable for credit when review version history
    git config --global

  • set an email address that will be associated with each history marker
    git config --global

  • set automatic command line coloring for Git for easy reviewing
    git config --global color.ui auto

git init:- initialize an existing directory as a Git

  • repository [ following Git command will create a repository in the current directory ]
    git init

  • retrieve an entire repository from a hosted location from URL
    git clone [url]

#02: Git Stage & Snapshot

  • git status:- show modified files in working directory, staged for your next commit
    git status

  • add a file as it looks now to your next commit (stage)
    git add [file]

  • unstage a file while retaining the changes in working directory
    git reset [file]

  • diff of what is changed but not staged
    git diff

  • diff of what is staged but not yet committed
    git diff --staged

  • commit your staged content as a new commit snapshot
    git commit -m "name of working details "

#03: Git Branch & Merge

Isolating work in branches, changing context, and integrating changes

  • list your branches. a * will appear next to the currently active branch
    git branch

  • create a new branch at the current commit
    git branch [branch name]

  • switch to another branch and check it out into your working directory
    git checkout

  • merge the specified branch’s history into the current one
    git merge [branch]

  • show all commits in the current branch’s history
    git log

Git Commands Cheat Sheet pdf

Top comments (0)