Git Fundamentals
Introduction to Version Control
Version control is a critical component of modern software development, enabling developers to track and manage changes in source code efficiently. Git, as a distributed version control system, provides robust mechanisms for collaborative coding and source code management.
Core Git Concepts
What is Git?
Git is an open-source version control system designed to handle projects of all sizes with speed and efficiency. It allows multiple developers to work on the same project simultaneously without conflicts.
Key Git Terminology
Term |
Description |
Repository |
A directory where Git tracks project files and version history |
Commit |
A snapshot of project changes at a specific point in time |
Branch |
An independent line of development |
Staging Area |
Preparation zone for files before committing |
Basic Git Workflow
graph LR
A[Working Directory] --> B[Staging Area]
B --> C[Local Repository]
C --> D[Remote Repository]
Installation and Configuration
## Update package list
sudo apt update
## Install Git
sudo apt install git
## Configure user name
git config --global user.name "Your Name"
## Configure email
git config --global user.email "[email protected]"
Creating a Git Repository
## Create new directory
mkdir my_project
cd my_project
## Initialize Git repository
git init
## Create initial file
echo "## My Project" > README.md
## Stage file
git add README.md
## Commit changes
git commit -m "Initial project setup"
Basic Git Commands
## Check repository status
git status
## View commit history
git log
## Create a new branch
git branch feature_branch
## Switch to a branch
git checkout feature_branch
## Merge branches
git merge feature_branch