I made this git cheat sheet for windows & MacOS users so that they can bookmark all the necessity git command in a single page. Yeah, it is true that Git is bigger than I cooked here. But most of the time we don’t need all of its features. And as a developer, I try to gather the most common cheat codes of Git & GitHub here. Furthermore, I also added some basics definitions for the beginner also so that the post can become a complete GIT encyclopedia for the git lovers around the world. Hope you’ll enjoy.  

Essential YouTube PlayList on Git & GitHub

What is a Version Control System

A version control system is a tool that will record all the changes in your code over time. As a result, if you make a mistake or if you want to revert your code to the previous state, the version control system give you the ground to fulfill your desire. It makes larger projects easily manageable and fixing bugs or updating the system becomes almost error free.

Git is now the common version control system and GitHub is the most popular git repository hosting service around the universe which attracts Microsoft enough to own Github by 7.5 billion USD. In addition to Github, there is some other git repo hosting service like Bitbucket or Gitlab. But I prefer GitHub more than the other services because the UI is smooth and easy to use.

How to Install Git

Before following the git cheat sheet, definitely, you need to install the git software in your system. But don’t worry because installing git in your system is easier than unpacking a bar of chocolate from the box. The steps are given below:

  • First, go to www.git-scm.com
  • It will automatically show the download option for your operating system.
  • Download it & install it like other software. Then open your command prompt if you are windows user or terminal if you are a Mac User. Then type ‘git version’. If it shows the version of the git, you successfully installed git in your device.  

How to Configure Git in Your Device

After installing git, you need to configure your device. Here the two core factors are your username & email account. Besides, you can also configure your default code editor for better management. Here is the list of all these required commands to configure your git system in your windows PC or MacOS.

COMMAND DESCRIPTION
git version To check whether the git is installed in your system or not.
git config –global user.name “Your Name” Set your global email address for git system.
git config –global user.email “email@you.com” Set your global user email for git system.
git config –global core.editor “code –wait” Set Visual Studio Code as your default git code editor.
git config –global core.editor “atom –wait” Set Atom as your default git code editor.
git config –global core.editor “subl -n -w” Set Sublime Text as your default git code editor.
git config –global core.editor “vim” Set Vim as your default git editor.
git config –global core.editor “mate -w” Set TextMate as your default git code editor.
git config –edit –global Open your global confirm using default editor

Read Also: VS Code Cheat Sheet for Developers

Git Basic Commands

After installation and configuration, you can start tracking your code changes by version controlling system. To do so you’ve to initialize an empty repository and then add the files that you want to track. And then you can commit your files and that’s how to keep the footprint of your version changes. To do all these things the following commands will be very helpful for you.

COMMAND DESCRIPTION
git init This command will initiate your current folder to a git repository.
git clone To copy a git repository from online you can run this command.
git status You can check the status of your files in the current staging area or working area by this command.
git add You can add your files to the staging area.
git add . You can add all your files to the staging area at the same time.
git commit -m ‘comment’ Save your progress by git commit.
git log Check the list of commits with the hash values of every commit.
git show Check the latest commit history with all code changes.
git show Check a particular commit history with all code changes.

Read Also: VS Code Cheat Sheet for Developers

Git Branches

To work with a team or to add a new feature, the safest approach is creating a branch and change your codes to that branch. And then after testing your branch code if you find everything okay, then merge that branch to your master branch again. And the following list of commands will help you to go through these processes easily and comfortably.

COMMAND DESCRIPTION
git branch Check the current branches in the local repository.
git branch -a Show the list of all branches in the local & connected remote repository.
git branch -r Show the list of your remote branch.
git checkout Switch from one branch to another.
git checkout -b Create a new branch. If a branch of the same name already exists, the command will not work.
git checkout -B Create a new branch by force. If a branch of the same name already exists, this command will delete and replace the old one by the new branch.
git branch -d Delete the branch. If you are in the same branch you can’t delete it.
git branch -D Force delete the branch. If your branch contains any conflict, it will ignore and delete it.
git merge Go to a branch and run this command. The current branch will merge to the branch of your command and become a single branch.

Read Also: VS Code Cheat Sheet for Developers

Git Remote & Github

So, your local git is now up and running. The next step is to upload your repository to a hosting service. There are lots of hosting services for that such as GitHub, Heroku, Docker, BitBucket, GitLab etc. Among all of this GitHub is the most popular among the developers. But you are open to sharing your codes to any of these hosting providers. The commands are always the same for any hosting services.

COMMAND DESCRIPTION
git remote add <remote_name> <git_repo_link> Check the current branches in the local repository.
git push -u <remote_name> <branch_name> Show the list of all branches in the local & connected remote repository.
git fetch Show the list of your remote branch.
git pull Switch from one branch to another.

 

I hope the post helped you in your journey to be a scalable developer. You can bookmark this git cheat sheet for windows and mac for your future use or you can also recommend your friends to follow this content. And if you want to propose a new command or point that I missed in my article, feel free to comment below. I’ll add them to my git cheat sheet. Happy Programming.