Git Version Control System Guide
Git is a distributed version control system that helps track changes in source code during software development. It enables multiple developers to work together on projects efficiently while maintaining a complete history of changes.
Key Features
Section titled “Key Features”- Distributed version control
- Branching and merging capabilities
- Complete history tracking
- Support for collaborative development
- Submodule support for project dependencies
Basic Commands
Section titled “Basic Commands”Repository Setup
Section titled “Repository Setup”# Initialize a new repositorygit init
# Clone an existing repositorygit clone https://github.com/username/repository.git
# Add remote repositorygit remote add origin https://github.com/username/repository.gitDaily Operations
Section titled “Daily Operations”# Check repository statusgit status
# Stage changesgit add filenamegit add . # Stage all changes
# Commit changesgit commit -m "Descriptive commit message"
# Push changes to remotegit push origin branch-name
# Pull latest changesgit pull origin branch-nameBranch Management
Section titled “Branch Management”# Create new branchgit checkout -b feature-branch
# List all branchesgit branch -a
# Switch branchesgit checkout branch-name
# Merge branchesgit merge feature-branch
# Delete branchgit branch -d branch-nameWorking with Submodules
Section titled “Working with Submodules”Submodules allow you to keep a Git repository as a subdirectory of another Git repository, useful for managing project dependencies or shared components.
Adding a Submodule
Section titled “Adding a Submodule”# Add a submodule to your projectgit submodule add https://github.com/username/library.git path/to/submodule
# Initialize submodulegit submodule init
# Update submodule to latest commitgit submodule updateUpdating Submodules
Section titled “Updating Submodules”# Update all submodules to their latest commitsgit submodule update --remote
# Pull changes with submodules when cloninggit clone --recurse-submodules repository-urlAdditional Tips
Section titled “Additional Tips”- Commit Messages: Write clear, descriptive commit messages that explain what changes were made and why
- Branching Strategy: Use feature branches for new development to keep main/master branch stable
- Submodule Management:
- Always commit submodule changes separately from main project changes
- Use specific commits or tags for submodules to ensure stability
- Update submodules carefully to avoid breaking changes
Common Use Cases
Section titled “Common Use Cases”Reverting Changes
Section titled “Reverting Changes”# Discard changes in working directorygit checkout -- filename
# Reset staged changesgit reset HEAD filename
# Revert a commitgit revert commit-hashStashing Changes
Section titled “Stashing Changes”# Save changes temporarilygit stash
# List stashed changesgit stash list
# Apply stashed changesgit stash popViewing History
Section titled “Viewing History”# View commit historygit log
# View changes in commitgit show commit-hash
# View file changesgit diff filenameThis guide covers the most common Git operations for daily development work. For more detailed information about specific commands or advanced usage, consult the official Git documentation.