# Git Basics

Git - developed by Linus Torvald in 2005  is a **Distributed version control system**. In distributed version control system, every person will have their own server which means they'll a copy of entire history of code locally.

### 3 stages of git -

![git 3 stages.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1663082039371/bjTPLDAlU.png align="left")

1. Working directory / Workspace

2. Staging

3. Local repository

When we commit, a **commit ID** is generated.

### Branch -

![git branch.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1663082027984/5P1qnX50X.png align="left")

1. When people are simultaneously working on a single project, we've to assign them various tasks without disturbing the flow of project.

2. When a **branch is made**, all works present at that particular stage, would be copied, and then people can work on it. (Add / Delete ) 

## Basic Commands

![git commands.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1663082540544/fGuxv9rYt.png align="left")

1. **git clone** - It creates a copy of an existing Git repository on our machine.

2. **git log** - Shows commit history.

3. **git push** - Copies changes from the local repository to the Remote / Central repository.

4. **git pull** - Copies changes from the Remote / Central repository, to local repository. Used for synchronization between 2 repositories.

5. **git checkout** - Used to Switch to another branch

6. **git merge** - To combine branches.

7. **git add** - Moves changes from the working directory to the staging area

8. **git commit** - To save changes made in the local repository.

9. **git init** - Initializes a new Git repository.

11. **git branch** - To create a branch.

11. **git remote** - Used to create, view, and delete connections to other repositories.

## Advance commands

1. **git rev-list --all | xargs git grep -F ' '** - Searching for a specific string inside git repository or in your commits.

2. **git rev-list --count <branch Name>** - To show the no. of commits made in that particular branch.

3. **git branch --merged <branch Name> | grep -v "branch name" | xargs -n 1 git branch -d**  - clean up local branches, deleting them all at once instead of deleting them one by one.

4. **git show <branch>: <file name>** - To look for a file in some other branch without switching the branch.

5. **git commit --allow- empty -m 'new empty commit'** - To do an empty commit. This command is useful when you want to **trigger a build by committing something**, so instead of editing things unnecessarily inside files to commit, we do a empty commit.

6. **git config --global help autocorrect 1** - To auto - correct spelling mistakes.

7. **git config --global fetch.prime true** - To prune orphaned objects. 
