Git Cheat Sheet
⭐ Introduction
Global information tracker (GIT) is a free and open source distributed version control system. It helps you to track changes made on files. Git allows developers to work on different parts of the same project efficiently.
There are three main sections in GIT: the working directory, staging area, and git directory.
We are going to learn some basic commands which will help you to configure, stage, and merge your code on GitHub or GitLab.
⭐ Setup & Init
Configure user information across all local repositories & initializing and clone repositories.
1 . git init will create a new local git repository in the current directory.
git init
2 . To retrieve an entire repository from a hosted location via URL eg. Github or Gitlab.
git clone [url]
3 . To set a name that is identifiable for credit when reviewing version history.
git config --global user.name “[firstname lastname]”
⭐ Stage & Snapshot
1 . To see the current state of the working directory and staging area.
git status
2 . To stage the modified files before the commit.
git add [file] /*To stage specific file */
git add . /* To stage all files */
git add *.txt /* add all .txt files in the repository */
git add [path] /*add a specific directory of files.*/
3 . To unstage the files.
git reset [file] /*To unstage specific file */
git reset . /* To unstage all files */
4 . To view all present conflicts.
git diff
5 . To view conflicts between branches before merging them.
git diff [source-branch] [target-branch]
- To commit the staged content
git commit -m “[descriptive message]”
⭐ Branch & Merge
1 . To create a new git branch
```
git branch
```
2 . To create a new branch at the current commit
git branch [branch name]
⭐ Share & Update
Retrieving updates from another repository and updating local repos
1 . To add origin URL
git remote add [url]
2 . To push local commits to the remote repository
git push [alias] [branch]
3 . To pull and merge commits from a remote branch
git pull
4 . To remove files from the project as well as from the commit
git rm [file]
Subscribe to my newsletter
Read articles from Shantanu Pade directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by