Understanding Git Fundamentals
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 repository management, Git enables developers to collaborate efficiently, manage code versions, and maintain project history.
Core Concepts of Git
Repository
A Git repository is a container for a project's files and their complete revision history. Repositories can be local or remote, allowing flexible code tracking and collaboration.
graph LR
A[Local Repository] <--> B[Remote Repository]
A <--> C[Staging Area]
A <--> D[Working Directory]
Basic Git Workflow
Stage |
Description |
Command |
Working Directory |
Where files are modified |
- |
Staging Area |
Preparing changes for commit |
git add |
Local Repository |
Permanent code snapshot |
git commit |
Remote Repository |
Shared project storage |
git push |
Git Configuration Example
## Set global user name and email
git config --global user.name "John Doe"
git config --global user.email "[email protected]"
## Initialize a new repository
git init my_project
cd my_project
## Create a new file
echo "## My First Project" > README.md
## Stage and commit changes
git add README.md
git commit -m "Initial project setup"
Key Git Commands for Version Control
Developers use Git commands to manage code versions, track changes, and collaborate on projects. Understanding these fundamental commands is crucial for effective repository management.
## Clone a repository
git clone
## Check repository status
git status
## View commit history
git log
## Create a new branch
git branch feature-branch
## Switch between branches
git checkout feature-branch