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.

Article illustration

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 feature to create a branch
  • git checkout feature to switch to it
  • git merge feature to 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.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *