Git is a distributed version control system used to track changes in source code during software development.
GitHub is a platform that provides Git repository hosting and additional collaborative features. This guide will cover the basics of Git and GitHub and include lab exercises to help you practice.
Version control systems track changes to files and enable multiple people to collaborate on projects. Git is a popular version control system that helps manage and track changes to your codebase.
A repository (repo) is a directory where your project files and history are stored. Git repositories can be local (on your machine) or remote (on platforms like GitHub).
Commits are snapshots of your project at a specific point in time.
Each commit includes:
Branches allow you to work on different features or fixes simultaneously.
The main branch is usually named:
But you can create additional branches for development purposes.
sudo apt-get install git
for Debian-based distributions.Set up your Git identity by configuring your name and email:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
To create a new Git repository, navigate to your project directory and run:
git init
Add files to the staging area (preparing them for a commit):
git add <file>
To add all files, use:
git add .
Commit your staged changes with a descriptive message:
git commit -m "Your commit message"
View your commit history with:
git log
Create and switch to a new branch:
git checkout -b <branch-name>
Merge changes from one branch into another:
git checkout main
git merge <branch-name>
Delete a branch that is no longer needed:
git branch -d <branch-name>
Sign up for a GitHub account at github.com.
Link your local repository to the GitHub repository:
git remote add origin <repository-URL>
Push your local commits to GitHub:
git push -u origin main
To clone an existing GitHub repository to your local machine:
git clone <repository-URL>
Fetch and merge changes from the remote repository:
git pull
By understanding these Git and GitHub fundamentals, you’ll be equipped to manage your projects effectively and collaborate with others. Practice these commands and concepts regularly to become proficient in version control and repository management.