Manual: How to Install Git and GitHub on Windows, Linux, and macOS, and Download a Private Repository
Table of Contents
1. Installing Git
a. Windows
-
Visit the official Git website to download Git for Windows.
-
Run the installer once downloaded.
-
Follow the installation prompts:
- Choose default options unless specific preferences are needed.
- Ensure that "Git Bash" and "Git GUI" are selected.
-
Once installed, open Git Bash (a terminal interface for Git commands) to verify the installation by running:
git --version
You should see the Git version number displayed.
Additional Resources:
b. Linux
Ubuntu/Debian-based systems:
-
Open your terminal.
-
Update your package list by running:
sudo apt update
-
Install Git using the following command:
sudo apt install git
-
Verify the installation:
git --version
Fedora/CentOS/RHEL:
-
Open the terminal.
-
Install Git by running:
sudo dnf install git
-
Verify the installation:
git --version
Additional Resources:
c. macOS
Method 1: Using Homebrew (Recommended)
-
Open the Terminal.
-
Install Homebrew if it's not installed yet by running:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install Git using Homebrew:
brew install git
-
Verify the installation:
git --version
Method 2: Xcode Command Line Tools
-
Open the Terminal.
-
Run the following command to install Git via Xcode Command Line Tools:
xcode-select --install
-
Follow the prompts to complete the installation.
-
Verify the installation:
git --version
Additional Resources:
2. Setting Up GitHub
a. Creating a GitHub Account
- Go to the GitHub website.
- Click on Sign Up and follow the prompts to create your account.
- After signing up, verify your email address to activate the account.
b. Generating SSH Keys for GitHub
SSH keys allow secure connections between your machine and GitHub without the need to enter a username and password repeatedly.
Windows, macOS, or Linux:
-
Open your terminal (Git Bash on Windows).
-
Generate a new SSH key by running:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Replace
"your_email@example.com"
with your actual GitHub email address. -
Press Enter to accept the default file location.
-
Set a passphrase if desired, or press Enter to skip.
-
Add the SSH key to the SSH agent:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa
-
Copy the SSH key to your clipboard:
-
For Linux/macOS:
cat ~/.ssh/id_rsa.pub
-
For Windows (Git Bash):
clip < ~/.ssh/id_rsa.pub
-
-
Go to your GitHub SSH settings and click New SSH Key.
-
Paste the SSH key into the key field and click Add SSH Key.
3. Cloning a Private GitHub Repository
There are two ways to clone a private repository from GitHub: using HTTPS or SSH.
a. Cloning Using HTTPS
-
Visit your private repository on GitHub.
-
Click the Code button, and copy the HTTPS URL.
-
Open your terminal and run the following command:
git clone https://github.com/username/repository.git
Replace
username
andrepository
with the respective repository's owner and name. -
When prompted, enter your GitHub username and Personal Access Token (you may need to generate this from your GitHub account settings under Developer Settings → Personal Access Tokens).
Additional Resources:
b. Cloning Using SSH
-
Ensure you've set up your SSH key (see Generating SSH Keys for GitHub).
-
Visit your private repository on GitHub.
-
Click the Code button, and copy the SSH URL (it starts with
git@github.com:
). -
Run the following command in your terminal:
git clone git@github.com:username/repository.git
Replace
username
andrepository
with the repository's owner and name. -
If prompted, enter the passphrase for your SSH key.
Additional Resources:
Conclusion
Now, you have successfully installed Git on your operating system, set up your GitHub account, and learned how to clone a private repository.