# Git Article

Git is the version control that system keeps track changes to a file or set of files over time so that we can go back to the specific versions later.

git has three stages:

1)Working tree/Untracked area: here we can create,update or delete the files,here doesn't track the changes yet.

2)Staging area: here we are preparing to commit the changes,git start tracking from here.

3)Commited Stage:here we commit the changes that we did.

GIT COMMANDS:

1.git init :it is used to intialize the git repository.

```bash
git init 
```

2.git add : it is used to add the changes from untracked area to staging area by using the keyword 'add'.

```bash
git add filename #add the specific file to staging area
git add . #it is used to add the all the files present in working tree
```

3.git commit : it is used to commit the changes from staging area to commit area using keyword 'commit'.

```bash
git commit -m "msg"
```

4.git branch : it is used to display the branchs in the current folder.

```bash
git branch #it list the branchs
git branch newbranchname #it just create the new branch
```

5.git checkout : it is used to switch the specified branch.

```bash
git checkout branch #switch to mentioned branch
git checkout -b newbranch #it create new brach and switch to that branch
```

6.git status : show modified files in working directory and staged for your next commit.

```bash
git status
```

7.git reset : it used to revert staging area to working area and commit area to staging area and working area.

```bash
git reset . #reset the all files from staging to unstage
git reset filename #reset the file to working area
git reset --soft HEAD~1 # reset the commit area to staging area
git reset --hard HEAD~1 #reset the commit area to working area
```

8.git log : it is used to give the commit history.

```bash
git log
git log --oneline #gives in one line
```

9.git push : it is used to push the local commits to remote repository.

```bash
git push -u origin <branch_name>
```

10.git pull : it is used to fetch and download content from remote repository and immediately update the local repository.

```bash
git pull origin <branch_name>
```

11.git remote add : it is used to add a new remote repository to your Git project.

```bash
git remote add <name> url
```

12.git merge :it is used to merge the branches.

```bash
git merge branchname #it is used merge current branch with branchname
```

13.git rebase : it is used to reapply commits on top of another base commit. It's often used to integrate changes from one branch onto another branch in a more linear and clean manner than merging.

```bash
git rebase <branch_name>
```

14.git diff : it will show the differences between the working directory and the staging area , or between the staging area and the most recent commit, depending on what's currently staged.

```bash
git diff #changes in working area
git diff --staged#difference between staging and most recent commit
```

15.git clone : it is used to create a copy of a Git repository. It copies the repository from a remote source to your local machine.

```bash
git clone <repository_URL>
```
