# CLI Command

## Git Setup

*Initializes a new Git repository in the current directory.*

```bash
git init
```

*Downloads a project and its history from a remote repository.*

```bash
git clone <url>
```

*Sets your Git username for all repositories on your system.*

```bash
git config --global user.name $USERNAME
```

*Sets your Git email for all repositories on your system.*

```bash
git config --global user.email $EMAIL
```

## Repository Initialization

*Shows the working directory status including staged, unstaged, and untracked files.*

```bash
git status
```

*Downloads a project and its entire history from a remote repository.*

```bash
git clone <url>
```

## Check Status and Logs

*Shows the commit history of the current branch.*

```bash
git log
```

*Shows a compact log with one line per commit.*

```bash
git log --oneline
```

*Displays details about a specific commit.*

```bash
git show <commit>
```

*Shows unstaged changes in your working directory.*

```bash
git diff
```

*Shows changes between staged files and the last commit.*

```bash
git diff --staged
```

## Add & Commit

*Stages a file for the next commit.*

```bash
git add <file>
```

*Stages all changes in the current directory.*

```bash
git add .
```

*Records staged changes with a message.*

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

*Stages and commits changes to tracked files in one step.*

```bash
git commit -am "message"
```

## Branching

*Lists all local branches.*

```bash
git branch
```

*Creates a new branch.*

```bash
git branch <branch-name>
```

*Switches to another branch.*

```bash
git checkout <branch-name>
```

*Creates and switches to a new branch.*

```bash
git checkout -b <branch-name>
```

*Merges the specified branch into the current branch.*

```bash
git merge <branch-name>
```

*Deletes a branch (if fully merged).*

```bash
git branch -d <branch-name>
```

*Force-deletes a branch.*

```bash
git branch -D <branch-name>
```

## Remote Repositories

*Shows the remote URLs of the repository.*

```bash
git remote -v
```

*Adds a new remote named 'origin'.*

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

*Pushes the current branch to the remote and sets tracking.*

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

*Uploads local commits to the remote repository.*

```bash
git push
```

*Fetches and integrates changes from the remote branch.*

```bash
git pull
```

*Downloads objects and refs from another repository.*

```bash
git fetch
```

## Reset, Revert, Rebase

*Moves HEAD back one commit, keeps changes staged.*

```bash
git reset --soft HEAD~1
```

*Moves HEAD back one commit, unstages changes.*

```bash
git reset --mixed HEAD~1
```

*Resets HEAD and discards all changes.*

```bash
git reset --hard HEAD~1
```

*Reverts a commit by creating a new inverse commit.*

```bash
git revert <commit>
```

*Re-applies commits from the current branch on top of another.*

```bash
git rebase <branch>
```

## Stashing Changes

*Saves uncommitted changes for later.*

```bash
git stash
```

*Lists all stashed changes.*

```bash
git stash list
```

*Applies the most recent stash without removing it.*

```bash
git stash apply
```

*Applies the most recent stash and removes it.*

```bash
git stash pop
```

*Deletes the most recent stash.*

```bash
git stash drop
```

## Tags

*Lists all tags.*

```bash
git tag
```

*Creates a new tag.*

```bash
git tag <tag-name>
```

*Creates an annotated tag with a message.*

```bash
git tag -a <tag-name> -m "message"
```

*Pushes a tag to the remote repository.*

```bash
git push origin <tag-name>
```

*Pushes all local tags to the remote.*

```bash
git push --tags
```

## Inspection

*Shows who made each change in a file.*

```bash
git blame <file>
```

*Summarizes commits by author.*

```bash
git shortlog -sne
```

*Shows a graph of the commit history.*

```bash
git log --graph --oneline --all
```

## Clean Up

*Removes untracked files and directories.*

```bash
git clean -fd
```

*Optimizes the repository by cleaning up unnecessary files.*

```bash
git gc
```

*Shows a log of all HEAD changes (even deleted branches).*

```bash
git reflog
```

## Cherry Picking

*Applies a specific commit on the current branch.*

```bash
git cherry-pick <commit>
```

## Submodules

*Adds a submodule at a specific path.*

```bash
git submodule add <url> <path>
```

*Initializes and updates submodules.*

```bash
git submodule update --init --recursive
```

*Pulls updates in all submodules.*

```bash
git submodule foreach git pull origin master
```
