Git is a distributed version control system used to manage and track changes in source code during software development. It allows you to create, modify, and manage multiple versions of your code base.
GitHub is a platform that hosts Git repositories online, making it easier for teams to collaborate, review code, and manage version control.
With Git and GitHub, you can work on projects with others, revert to previous versions if necessary, and keep your code organized.
Follow these instructions to install Git on your operating system.
Most Linux distributions include Git in their package managers. Use the following command to install:
sudo apt update
sudo apt install git
Download Git from https://git-scm.com/download/win and run the installer. Follow the on-screen instructions.
On macOS, Git can be installed via Homebrew:
brew install git
After installation, configure Git with your username and email:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
These settings will identify you as the author of any commits you make in Git.
Here are some essential Git commands to get you started:
To start tracking changes in a directory, initialize a new Git repository:
git init
View the current status of your files, including any changes:
git status
To add changes to the staging area, use:
git add filename
To add all changes, use:
git add .
Record your changes with a commit message:
git commit -m "Your commit message"
See a log of past commits:
git log
To use GitHub, you’ll need a GitHub account. Sign up here if you haven’t already.
Go to GitHub, create a new repository, and name it as desired. Copy the repository URL, as you’ll need it in the next step.
In your terminal, link your local repository to GitHub by adding the remote URL:
git remote add origin https://github.com/username/repository-name.git
To upload your local commits to GitHub, use:
git push -u origin master
Once your repository is connected to GitHub, use the following workflow:
git add
.git commit
.git push
.git pull
.