# Initial page

## Mastering Git

**Git** is a free open source distributed version control tool that tracks changes in your file.\
As a developer believe me you need it more than anything else ('*Just kidding* 😛'). But its important.

### Git Terminal commands

*Here is a cheat sheet of commands you might find useful and come to love:*<br>

```
    git config --global user.name "exampleuser"
```

-sets a name identifiable for credit when reviewing version history<br>

```
    git config --global user.email "exampleuser@email.com"
```

-set an email address associated with the version history<br>

```
    git config --global color.ui auto
```

-set automatic coloring of git in the command line<br>

```
    git init
```

-initialize a local directory on you computer as a git repository<br>

```
    git clone
```

-retrieve a repository from a central remote hosting<br>

```
    git status
```

-show modifications on the working tree<br>

```
    git add <fileName>
```

-add the named file to the staging area<br>

```
    git add .
```

-adds all tracked files to the staging area<br>

```
    git reset
```

-unstage a file but retains changes in the working directory<br>

```
    git diff
```

-shows changes between commits,commit and working tree<br>

```
    git diff --staged
```

-show changes made to a file in the staging area<br>

```
    git commit -m "commit message"
```

-commits your staged content as a new commit snapshot<br>

```
    git branch <branchName>
```

-creates a new branch

* Branches enables you to isolate your changes and context and integrate them together when you're ready\*

```
    git branch -a
```

-lists all your branches<br>

```
    git checkout <branchName>
```

-switches to the named branch<br>

```
    git merge <branchName>
```

-merge the specified branch with the current one<br>

```
    git log
```

-shows all commits in the current branch<br>

```
    git log branchB..branchA
```

-shows commits on branchA that are not on branchB<br>

```
    git log --follow <fileName>
```

-shows commits that changed a file,even if it was renamed<br>

```
    git diff branchB...branchA
```

-shows changes that are in branchA and not in branchB<br>

```
    git show <SHA>
```

-shows any object in git in human-readble format<br>

```
    git rm <fileName>
```

-removes the file from the project and stage the change<br>

```
    git mv <currentPath> <newPath>
```

-changes an existing path and stage the move<br>

```
    git log --stat -M
```

-shows all commits log and paths changed<br>

```
    git remote add <alias> <url>
```

-add a remote git url to your local repository<br>

```
    git fetch <alias>
```

-fetch all the branches from a central remote repositoy<br>

```
    git merge <alias>/<branch>
```

-merge a remote branch into your current one locally<br>

```
    git push <alias> branch
```

-transmit local branch to the remote repo branch<br>

```
    git pull
```

-fetch and merge any commits from the remote tracking branch<br>

```
    git rebase <branch>
```

-apply any commits on current branch ahead of specified one<br>

```
    git reset --hard <commit>
```

-clear staging area,rewrite working tree from specified commit<br>

```
    git stash
```

-save modified and staged changes<br>

```
    git stash list
```

-list stack order of stashed file changes<br>

```
    git stash pop
```

-write working from top of stash stack<br>

```
    git stash drop
```

-discard changes from top of stash stack

sumber <https://dev.to/davisbwake/git-cheat-sheet-3jgc>
