Git Basics
What is Git?
Git is a distributed version control system (VCS) designed to track changes in source code during software development. As a powerful tool for code management, Git enables developers to collaborate efficiently, manage project versions, and maintain a comprehensive history of code modifications.
Core Concepts of Version Control
graph TD
A[Local Repository] --> B[Staging Area]
B --> C[Remote Repository]
C --> D[Commit History]
Git Component |
Description |
Repository |
Container for project files and version history |
Commit |
Snapshot of project changes at a specific point |
Branch |
Parallel development line |
Remote |
Shared project location |
Installation and Configuration
To install Git on Ubuntu 22.04, use the following commands:
sudo apt update
sudo apt install git
git --version
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Basic Git Commands
## Initialize a new repository
git init my_project
cd my_project
## Add files to staging area
git add README.md
git add .
## Commit changes
git commit -m "Initial project setup"
## Check repository status
git status
Working with Branches
## Create a new branch
git branch feature_login
## Switch to a branch
git checkout feature_login
## Create and switch to a new branch
git checkout -b feature_authentication
Understanding Git Workflow
Git supports a distributed development model where developers can work independently, merge changes, and maintain a comprehensive project history. Its lightweight branching mechanism allows for flexible and parallel development across multiple features or experiments.