How to Use Git for Version Control: A Practical Tutorial for Beginners
Git is a distributed version control system that records changes to files so you can track history, revert mistakes, and collaborate without overwriting work. It is essential for modern software development.
First, install Git and configure your identity with git config --global user.name "Your Name" and git config --global user.email "you@example.com". Then navigate to your project folder in the terminal.
Core Git Workflow
1. Create a Repository
Run git init to start tracking a project. This creates a hidden .git directory that stores version history.
2. Stage and Commit Changes
Check modified files with git status. Stage them using git add ., then save a snapshot with git commit -m "Describe your change".
3. Branch and Merge
Branches let you work safely on new features. Use:
git branch featureto create a branchgit checkout featureto switch to itgit merge featureto combine changes
4. Connect to a Remote
Link a GitHub or GitLab repository with git remote add origin URL. Upload commits using git push -u origin main, and download updates with git pull.
Conclusion
Git becomes intuitive with practice. Start with init, add, commit, branch, and push. These core commands cover most daily version control needs.