> ## Documentation Index
> Fetch the complete documentation index at: https://ai.tharung.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Git & Github

# 1. What is Git?

**Git** is a **Distributed Version Control System (DVCS)** used to track changes in source code.

It allows developers to:

* Track file changes
* Restore previous versions
* Collaborate with others
* Manage different project versions

Git works locally on your computer and stores the entire project history. (\[GitHub Docs]\[1])

***

# 2. What is GitHub?

GitHub is a cloud platform that hosts Git repositories.

It provides:

* Cloud backup
* Collaboration
* Pull Requests
* Issues
* Code Review
* GitHub Actions (CI/CD)

**Difference**

| Git             | GitHub                 |
| --------------- | ---------------------- |
| Software        | Website/Cloud Platform |
| Works locally   | Works online           |
| Version Control | Repository Hosting     |
| Open Source     | Collaboration Platform |

(\[GitHub Docs]\[1])

***

# 3. Version Control System (VCS)

A Version Control System keeps track of every modification.

Benefits:

* Undo mistakes
* Track history
* Multiple developers can work together
* Backup
* Branching

***

# 4. Install Git

Download Git

Windows: [https://git-scm.com](https://git-scm.com)

Verify installation

```bash theme={null}
git --version
```

***

# 5. Configure Git

```bash theme={null}
git config --global user.name "Your Name"

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

Check configuration

```bash theme={null}
git config --list
```

***

# 6. Git Repository

A Repository (Repo) is a project folder tracked by Git.

Types

* Local Repository
* Remote Repository

***

# 7. Initialize Repository

```bash theme={null}
git init
```

Creates

```text theme={null}
.git
```

hidden folder.

***

# 8. Git Workflow

```text theme={null}
Working Directory
        ↓
git add
        ↓
Staging Area
        ↓
git commit
        ↓
Local Repository
        ↓
git push
        ↓
GitHub Repository
```

***

# 9. Git Status

```bash theme={null}
git status
```

Shows:

* Modified files
* New files
* Deleted files
* Staged files

***

# 10. Git Add

Stage one file

```bash theme={null}
git add file.txt
```

Stage all files

```bash theme={null}
git add .
```

***

# 11. Git Commit

Save snapshot

```bash theme={null}
git commit -m "Initial Commit"
```

***

# 12. Git Log

Show commit history

```bash theme={null}
git log
```

Short history

```bash theme={null}
git log --oneline
```

***

# 13. Clone Repository

Download GitHub project

```bash theme={null}
git clone repository_url
```

Example

```bash theme={null}
git clone https://github.com/user/project.git
```

***

# 14. Remote Repository

Check remote

```bash theme={null}
git remote -v
```

Add remote

```bash theme={null}
git remote add origin URL
```

***

# 15. Push

Upload code

```bash theme={null}
git push origin main
```

First Push

```bash theme={null}
git push -u origin main
```

***

# 16. Pull

Download latest code

```bash theme={null}
git pull origin main
```

***

# 17. Fetch

Download changes only

```bash theme={null}
git fetch
```

Difference

Fetch → Downloads only

Pull → Downloads + Merge

***

# 18. Branch

Create branch

```bash theme={null}
git branch feature
```

List branches

```bash theme={null}
git branch
```

Delete branch

```bash theme={null}
git branch -d feature
```

***

# 19. Switch Branch

```bash theme={null}
git checkout feature
```

or

```bash theme={null}
git switch feature
```

***

# 20. Create and Switch

```bash theme={null}
git checkout -b feature
```

or

```bash theme={null}
git switch -c feature
```

***

# 21. Merge

Merge feature branch

```bash theme={null}
git checkout main

git merge feature
```

***

# 22. Merge Conflict

Occurs when two developers modify the same line.

Resolve by:

1. Edit file
2. Remove conflict markers
3. Add file
4. Commit

***

# 23. Git Ignore

Ignore files

Example

```text theme={null}
node_modules/

.env

*.log

dist/
```

File name

```text theme={null}
.gitignore
```

***

# 24. Remove File

```bash theme={null}
git rm file.txt
```

***

# 25. Rename File

```bash theme={null}
git mv old.txt new.txt
```

***

# 26. Undo Changes

Discard changes

```bash theme={null}
git restore file.txt
```

Unstage

```bash theme={null}
git restore --staged file.txt
```

***

# 27. Reset

Soft

```bash theme={null}
git reset --soft HEAD~1
```

Mixed

```bash theme={null}
git reset HEAD~1
```

Hard

```bash theme={null}
git reset --hard HEAD~1
```

***

# 28. Revert

Undo commit safely

```bash theme={null}
git revert commitID
```

***

# 29. Stash

Save work temporarily

```bash theme={null}
git stash
```

View stash

```bash theme={null}
git stash list
```

Restore

```bash theme={null}
git stash pop
```

Delete

```bash theme={null}
git stash clear
```

***

# 30. Tags

Create

```bash theme={null}
git tag v1.0
```

Push

```bash theme={null}
git push origin v1.0
```

***

# 31. Fork

Fork creates your own copy of another person's GitHub repository.

Used in Open Source.

***

# 32. Pull Request (PR)

Request to merge code into another branch.

Steps

Fork

↓

Clone

↓

Create Branch

↓

Commit

↓

Push

↓

Open Pull Request

↓

Review

↓

Merge

***

# 33. GitHub Issues

Used to:

* Report bugs
* Request features
* Track tasks

***

# 34. README.md

Project documentation

Contains

* Project name
* Installation
* Usage
* Features
* License

***

# 35. Markdown Basics

Heading

```text theme={null}
# Heading
```

Bold

```text theme={null}
**Bold**
```

Italic

```text theme={null}
*Italic*
```

Code

```text theme={null}
`Code`
```

Code Block

````text theme={null}
```python
print("Hello")
```
````

***

# 36. Common Git Commands Cheat Sheet

```bash theme={null}
git init

git clone URL

git status

git add .

git commit -m "message"

git log

git branch

git checkout branch

git switch branch

git checkout -b newbranch

git merge branch

git remote -v

git push

git pull

git fetch

git stash

git stash pop

git reset

git revert

git rm

git mv

git tag
```

***

# 37. Complete Git Workflow

```text theme={null}
Create Project

↓

git init

↓

git add .

↓

git commit

↓

Create GitHub Repository

↓

git remote add origin URL

↓

git push

↓

Make Changes

↓

git add

↓

git commit

↓

git push
```

***
