Skip to content

Commit a97cc27

Browse files
git basics v2
1 parent adea226 commit a97cc27

25 files changed

+1295
-278
lines changed
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# What is Git?
2+
3+
Git is a **distributed version control system** that tracks changes in source code during software development. It allows multiple developers to collaborate on a project efficiently while maintaining a complete history of changes.
4+
5+
## Key Features of Git
6+
7+
### 1. **Version Control**
8+
Git records changes to files, enabling you to:
9+
- Keep track of the history of your project.
10+
- Revert files or entire projects to previous versions.
11+
12+
### 2. **Distributed System**
13+
Unlike centralized systems, Git:
14+
- Stores the complete project history on every developer's machine.
15+
- Enables offline access to project history and changes.
16+
17+
### 3. **Branching and Merging**
18+
Git allows:
19+
- Creating independent branches to develop features or fix bugs.
20+
- Merging branches back into the main project after review.
21+
22+
### 4. **Lightweight and Fast**
23+
Git operations are:
24+
- Local and fast due to distributed architecture.
25+
- Efficient even for large projects.
26+
27+
## Why Use Git?
28+
29+
- **Collaboration**: Enables teams to work on the same project simultaneously without overwriting each other's changes.
30+
- **Traceability**: Tracks who made changes, what was changed, and when.
31+
- **Flexibility**: Adapts to various workflows like Gitflow, feature branching, or trunk-based development.
32+
33+
## How Git Works
34+
35+
1. **Repository**: A Git project lives in a repository (repo), containing all project files and the history of changes.
36+
2. **Staging Area**: Changes are added to a staging area before committing them.
37+
3. **Commits**: A commit is a snapshot of the project, saved in the repository.
38+
39+
### Example Workflow
40+
41+
1. **Initialize a repository**:
42+
```bash
43+
git init
44+
```
45+
46+
2. **Track changes in a file**:
47+
```bash
48+
git add file.txt
49+
```
50+
51+
3. **Commit changes**:
52+
```bash
53+
git commit -m "Add file.txt"
54+
```
55+
56+
4. **View history**:
57+
```bash
58+
git log
59+
```
60+
61+
## History of Git
62+
63+
Git was created in **2005** by **Linus Torvalds**, the creator of the Linux kernel. It was designed to replace proprietary version control systems and meet the following criteria:
64+
- High performance.
65+
- Strong support for distributed development.
66+
- Robust against corruption.
67+
68+
## Conclusion
69+
70+
Git is an indispensable tool for modern software development, providing the ability to manage projects effectively and collaboratively. Mastering Git is an essential skill for any developer.
71+
72+
---
73+
74+
**Next Steps**: [Why Use Git?](./2.%20Why%20Use%20Git.md)
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Why Use Git?
2+
3+
Git has become the industry standard for version control and is widely used in software development, data analysis, and collaborative projects. Here are the key reasons why you should use Git.
4+
5+
## 1. **Collaboration Made Easy**
6+
7+
- **Teamwork**: Git allows multiple developers to work on the same project simultaneously without overwriting each other's work.
8+
- **Branching**: Developers can create separate branches for features, fixes, or experiments, which can later be merged into the main project.
9+
- **Conflict Resolution**: Git provides tools to resolve conflicts when changes from different contributors overlap.
10+
11+
## 2. **Version Control**
12+
13+
- **Track Changes**: Git keeps a complete history of all changes made to your files, enabling you to track who made changes, when, and why.
14+
- **Revert Changes**: You can easily undo changes or revert to previous versions of your project.
15+
- **Experiment Safely**: Create branches to experiment with new ideas without risking the main codebase.
16+
17+
## 3. **Distributed Development**
18+
19+
- **Work Offline**: With Git, each developer has a full copy of the repository on their local machine, allowing work without internet access.
20+
- **Redundancy**: Since every copy of the repository is complete, the risk of losing your project due to server failure is minimized.
21+
22+
## 4. **Speed and Performance**
23+
24+
- **Fast Operations**: Git performs most operations locally, making tasks like commits, diffs, and log retrieval quick and efficient.
25+
- **Handles Large Projects**: Git is optimized for speed, even with large repositories containing many files.
26+
27+
## 5. **Flexibility**
28+
29+
- **Supports Any Workflow**: Git adapts to different workflows, whether it’s feature branching, Gitflow, or trunk-based development.
30+
- **Customizable**: Developers can create custom Git commands (aliases) or use Git hooks for automation.
31+
32+
## 6. **Integration with Tools**
33+
34+
- **Development Platforms**: Git integrates seamlessly with popular platforms like GitHub, GitLab, and Bitbucket, providing additional collaboration and CI/CD features.
35+
- **IDEs**: Most modern Integrated Development Environments (IDEs) come with built-in Git support, simplifying version control.
36+
37+
## 7. **Transparency and Traceability**
38+
39+
- **Audit Trail**: Git's commit history provides a detailed and transparent record of project changes.
40+
- **Blame Feature**: Identify who made specific changes to a file using commands like `git blame`.
41+
42+
## 8. **Open Source and Free**
43+
44+
Git is open-source, which means:
45+
- It’s free to use for personal, academic, or commercial purposes.
46+
- It benefits from continuous improvements and contributions from the global developer community.
47+
48+
## Real-World Scenarios
49+
50+
### Software Development
51+
Teams use Git to:
52+
- Collaborate on coding projects.
53+
- Automate testing and deployment with CI/CD pipelines.
54+
55+
### Research and Data Analysis
56+
- Scientists use Git to version datasets and analysis scripts.
57+
- It ensures reproducibility and accuracy in research.
58+
59+
### Documentation and Writing
60+
- Authors and documentation teams use Git to track changes in written content and collaborate efficiently.
61+
62+
## Conclusion
63+
64+
Git is more than just a tool—it's a cornerstone of modern development workflows. Its robust features, speed, and flexibility make it an essential tool for individual developers and teams.
65+
66+
---
67+
68+
**Next Steps**: [Setting Up Git](./3.%20Setting%20Up%20Git.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Setting Up Git
2+
3+
To start using Git, you need to install and configure it on your system. This guide walks you through the steps to get Git up and running.
4+
5+
---
6+
7+
## 1. **Install Git**
8+
9+
Git is available for most operating systems. Follow the steps for your platform below:
10+
11+
### **Linux**
12+
1. Open your terminal.
13+
2. Install Git using your package manager:
14+
- **Debian/Ubuntu**:
15+
```bash
16+
sudo apt update
17+
sudo apt install git
18+
```
19+
- **Red Hat/CentOS**:
20+
```bash
21+
sudo yum install git
22+
```
23+
- **Arch Linux**:
24+
```bash
25+
sudo pacman -S git
26+
```
27+
28+
### **Windows**
29+
1. Download the Git installer from the [official Git website](https://git-scm.com/).
30+
2. Run the installer and follow the setup wizard.
31+
3. Select options for your preferred text editor, line endings, and environment path.
32+
33+
### **macOS**
34+
1. Install Git via Homebrew:
35+
```bash
36+
brew install git
37+
```
38+
2. Alternatively, download and install Git from [git-scm.com](https://git-scm.com/).
39+
40+
---
41+
42+
## 2. **Verify Installation**
43+
44+
After installation, confirm that Git is installed correctly:
45+
```bash
46+
git --version
47+
```
48+
You should see the installed Git version, such as `git version 2.x.x`.
49+
50+
---
51+
52+
## 3. **Configure Git**
53+
54+
To use Git effectively, you must set up some basic configurations.
55+
56+
### **Set Your Identity**
57+
These details will appear in your commit history.
58+
```bash
59+
git config --global user.name "Your Name"
60+
git config --global user.email "[email protected]"
61+
```
62+
63+
### **Set Default Text Editor**
64+
Choose a text editor for writing commit messages:
65+
- For **Nano**:
66+
```bash
67+
git config --global core.editor nano
68+
```
69+
- For **Vim**:
70+
```bash
71+
git config --global core.editor vim
72+
```
73+
- For **VS Code**:
74+
```bash
75+
git config --global core.editor "code --wait"
76+
```
77+
78+
### **Enable Colored Output**
79+
Improve the readability of Git commands:
80+
```bash
81+
git config --global color.ui auto
82+
```
83+
84+
---
85+
86+
## 4. **Check Git Configuration**
87+
88+
View your global configuration settings:
89+
```bash
90+
git config --list
91+
```
92+
This command shows all configured settings, such as your username, email, and editor.
93+
94+
---
95+
96+
## 5. **Create Your First Repository**
97+
98+
### **Initialize a Repository**
99+
1. Navigate to the directory where you want to store your project:
100+
```bash
101+
cd /path/to/project
102+
```
103+
2. Initialize Git:
104+
```bash
105+
git init
106+
```
107+
108+
### **Clone an Existing Repository**
109+
To copy an existing repository:
110+
```bash
111+
git clone https://github.com/user/repository.git
112+
```
113+
114+
---
115+
116+
## 6. **Generate SSH Keys (Optional)**
117+
118+
To securely interact with remote repositories (e.g., GitHub, GitLab), you can generate SSH keys:
119+
1. Generate an SSH key:
120+
```bash
121+
ssh-keygen -t rsa -b 4096 -C "[email protected]"
122+
```
123+
2. Add the SSH key to your agent:
124+
```bash
125+
ssh-add ~/.ssh/id_rsa
126+
```
127+
3. Copy the public key to your clipboard:
128+
```bash
129+
cat ~/.ssh/id_rsa.pub
130+
```
131+
4. Add the key to your Git hosting service (e.g., GitHub, GitLab).
132+
133+
---
134+
135+
## 7. **Set Up Aliases (Optional)**
136+
137+
Git aliases can simplify commonly used commands:
138+
```bash
139+
git config --global alias.st status
140+
git config --global alias.co checkout
141+
git config --global alias.br branch
142+
git config --global alias.cm commit
143+
```
144+
145+
---
146+
147+
## Conclusion
148+
149+
Once Git is installed and configured, you're ready to start managing your projects. By completing these steps, you’ve set up a foundation for using Git efficiently.
150+
151+
---
152+
153+
**Next Steps**: [Initializing Repositories](../02.%20Basic%20Git%20Commands/1.%20Initializing%20Repositories.md)

0 commit comments

Comments
 (0)