<!-- @format -->

# Git Assignment

## 1. What is Git and Version Control

What problem does Git solve?
Git solves the problem of tracking changes in files (especially code) and managing collaboration between multiple people. Without Git, it’s difficult to know who made what changes, when, and why. Git lets you save different versions of your project, go back to earlier versions if something breaks, and merge changes from different people without overwriting each other’s work.

Real-life example where multiple people edit the same file:
A school group project where everyone is writing different sections of a report in the same Word/Google Doc file. Each student edits parts of the document, and the changes need to be combined into one final version.

Why is version control better than emailing files back and forth?
With email, you end up with many copies of the same file (e.g., report_final.docx, report_final2.docx, report_really_final.docx), which is confusing.It’s easy to lose track of who made which changes.If two people edit the same section, you must manually merge them, which can cause mistakes.

Version control (like Git) keeps one central version of the file, records who made each change, and can automatically merge changes. This makes collaboration smoother, avoids confusion, and provides a history to undo mistakes if needed.


## Git Version Check

![Git version check](git_version.png)

---

## 2. Installing Git & Configuring User Info

![Git status](git_username.png)

---

## Git List

![Git status](git_list.png)

---

## 3. Initializing a Repository

## Git Init

![Git add](git_init_status.png)

---

## 4. Working Directory, Staging, and Commits

## Git Add

![Git add](git_adding_notes.png)
![Git add](git_add.png)
![Git add](git_commit_notes.png)
![Git add](git_file_status.png)

---

## 5. Adding & Committing Files

## Git Log 
![Git log](gitlog.png)
![Git log](git_log.png)

---

## 6. Viewing Commit Logs & Diffs

## Git Log (graph)

![Git log graph](onelinegraph.png)

---

## Git Diff

![Git diff](git_diff.png)

---

## Git Diff (commit1 vs commit2)

![Git diff between two commits](git_diff_between_commits.png)

---

## 7. Creating & Switching Branches

## Git Branch 

![Git branch](git_branch.png)
![Git new branch](git_new_branch.png)
![Git checkout](git_checkout.png)
![Git branch](git_checkout_switch.png)

---

## 8. Cloning a Remote Repository

## Git Clone 

![Git clone](git_clone.png)

---

## 9. Adding & Managing Remotes

## Git Remote 

![Git origin](git_origin.png)
![Git remote](git_origin_remote.png)

---

## 10. Pushing & Pulling Changes

## Git Pull

![Git pull](git_pull.png)

## Git Push

![Git push](gitpush.png)

---

## 11. Ignoring Files with .gitignore

## .gitignore 

![.gitignore](gitignore.png)

## Before git ignore

![.gitignore](before_git_ignore.png)

## After git ignore

![.gitignore](after_git_ignore.png)

---

## Part 1: Viewing File History

## git log -- filename.extension

![.git log -- example.txt](git_log_example.png)

## git log -p -- filename.extension

![git log -p](git_log_example_p1.png)
![git log -p](git_log_example_p2.png)
![git log -p](git_log_example_p3.png)

## git log --oneline -- filename.extension

![git log --oneline](git_log_example_oneline.png)

---

How many commits modified this file?
5

What differences do you see when adding the -p option?
It shows the detailed changes made to the file during the commit

---

## Part 2: Viewing File History with Blame

## git blame -- filename.extension

![.git blame -- assignment.txt](git_blame.png)

## git blame -L 1,5 -- filename.extension

![git blame -L 1,5](git_bame_L.png)

## git blame -e -- filename.extension

![git blame -e](git_blame_e.png)

---

Who changed each line of the file?
Gokul

How does -L help when the file is large?
It acts as a selection area to select the lines between the given numbers

What extra information does -e provide?
It shows the commiters email id

---

## Part 3: Merging Branches

## git merge

![merge fast forward](git_fast_fwd.png)
![git_merge_graph_oneline](git_merge_graph_oneline.png)
![merge 1](merge_conflict_1.png)
![merge 2](git_merge_conflict_2.png)
![merge 3](conflict3.png)

---
