Git & GitHub Tutorial – Version Control for Beginners
Learn Git and GitHub basics with this complete tutorial. Covers version control, repositories, commits, branches, merging, and collaboration. Ideal for beginners, developers, and AI enthusiasts to manage code efficiently and work in teams.
1. Introduction to Git & GitHub
Git is a version control system that tracks changes in your code. GitHub is a cloud platform for hosting Git repositories, enabling collaboration with other developers.
Benefits:
- Track code changes over time.
- Revert to previous versions if needed.
- Collaborate with other developers.
- Work on multiple features simultaneously using branches.
Best Practices:
- Commit small, meaningful changes.
- Write clear commit messages.
- Regularly push changes to remote repositories.
2. Installing Git
- Windows / Mac / Linux: Download from git-scm.com
- Verify installation:
3. Configuring Git
Set your name and email (used for commits):
Check configuration:
4. Basic Git Commands
Initialize a Repository
Creates a local Git repository.
Check Status
Add Files
Commit Changes
View Commit History
Best Practices:
- Commit frequently to save progress.
- Use descriptive commit messages like
"Fix login bug"or"Add data preprocessing script".
5. Branching & Merging
Branches allow multiple features to be developed simultaneously.
Create a Branch
Or combine into one command:
Merge Branches
Best Practices:
- Keep
mainbranch stable. - Work on separate branches for new features or bug fixes.
- Regularly merge branches to avoid conflicts.
6. GitHub Basics
GitHub hosts your Git repositories online for collaboration.
Create a Repository
- Sign up / log in to GitHub.
- Click New Repository, enter name, description, and visibility.
Push Local Repo to GitHub
Clone Repository
Pull Changes
Best Practices:
- Use meaningful repository names.
- Add a README.md to describe the project.
- Use
.gitignoreto exclude unnecessary files.
7. Collaboration Workflow
- Fork a repository.
- Clone it locally.
- Create a branch for your changes.
- Commit and push changes.
- Open a Pull Request on GitHub.
Best Practices:
- Review pull requests carefully.
- Communicate changes clearly in PR descriptions.
- Always sync your fork with the main repository regularly.
8. Summary & Best Practices
- Git tracks code changes; GitHub hosts repositories online.
- Use branches for features and bug fixes.
- Commit frequently with meaningful messages.
- Push and pull changes to keep code synced with the team.
- Collaborate efficiently using forks and pull requests.
By mastering Git & GitHub, beginners can manage projects effectively, track changes, and collaborate with other developers in AI, software, and web projects.