Git Use Cases and Documentation

Introduction

Git is a distributed version control system widely used for tracking changes in source code during software development. Below are some common use cases and their corresponding commands.


Use Cases

1. Version Control

- Track changes in your project files.
- Revert to previous versions if needed.

```bash
git init
git add .
git commit -m "Initial commit"
```

2. Collaboration

- Work with multiple developers on the same project.
- Merge changes from different branches.

```bash
git clone <repository-url>
git pull origin main
git push origin main
```

3. Branching

- Create separate branches for new features or bug fixes.
- Merge branches when the work is complete.

```bash
git branch feature-branch
git checkout feature-branch
git merge feature-branch
```

4. Code Review

- Use pull requests to review and discuss code changes before merging.

```bash
git checkout -b feature-branch
git push origin feature-branch
```

5. Undo Changes

- Revert changes or reset to a previous commit.

```bash
git checkout -- <file>
git reset --hard <commit-hash>
```

Common Commands

Command Description
git status Check the status of your working directory.
git log View commit history.
git diff Show changes between commits or branches.
git stash Temporarily save changes.
git remote -v View remote repository details.

Resources