Git Cheat Sheet

Git Cheat Sheet

A Guide to understand the basic of Git

Overview

This cheat sheet will help any new user to understand the basic git commands. In this article, you'll learn what is git is and how to use it.

What is Git?

GIT is a free and open-source distributed version control system, which also helps multiple developer working in same project using branching facility and supports non-linear development to speed up the development process.

Git Installation & Setup

Git Installation

git_download.png You can download and install GIT in your working system from the below link for any platform (Mac, windows Or Linux):
https://git-scm.com/downloads.
And this is the very first step to getting start with the GIT.

Git Setup

It is pretty easy to setup git in local machine, just you have to understand and run the below commands and that's all to make you have to do to setup GIT.

Configuring user information used across all local repositories

git config --global user.name "[firstname lastname]"


set a name that is identifiable for credit when review version history
git config --global user.email "[valid-email]"


set an email address that will be associated with each history marker
git config --global color.ui auto


set automatic command line coloring for Git for easy reviewing

Git Basic Commands

Congratulation!🎊 Hope you able to configure git in your machine now. Once you able to setup GIT in your local machine you are now ready to learn basic git commands to handle version control for your project using git. So let's start rocking 🀟 with GIT.

The first command you need to know is how to initiate a Git repository. To start with open command prompt and navigate to your project root directory folder to initiate git and type the below command -
git init


to initialize an existing directory as a Git repository

git clone [your repository url]


to retrieve an entire repository from a hosted location via URL
git status


to show modified files in working directory, staged for your next commit
git add [file]


to add a file as it looks now to your next commit (stage). If you have a hell lot file and want to add all of them, just replace [file] with a . and git consider all untracked file and will be added all.
git reset [file]


to unstage a file while retaining the changes in working directory. To unstage all files just you need to type . in place of [file] for the above command.
git commit -m β€œ[descriptive message]”


to commit your staged content as a new commit snapshot
git branch


to list your branches. a * will appear next to the currently active branch
git branch [branch-name]


to create a new branch at the current commit
git remote add [alias] [url]


to add a git URL as an alias
git fetch [alias]


to fetch down all the branches from that Git remote
git merge [alias]/[branch]
to merge a remote branch into your current branch to bring it up to date
git push [alias] [branch]


to transmit local branch commits to the remote repository branch
git pull


to fetch and merge any commits from the tracking remote branch
git checkout


to switch to another branch and check it out into your working directory
git merge [branch]


to merge the specified branch’s history into the current one
git log


to show the commit history for the currently active branch

Conclusion

Thanks a lot for reading and hope now you know how to use git as version controlling tool for your next project. For more information please checkout the official Git Documentation site. And don't forget to hit a πŸ‘ if you find this article helpful. Happy learning! πŸŽ‰

Β