Week 10 | Setup Git in personal laptop
📅 Date: 09 June, 2025
⏰ Time: 15:30h - 17:30h
📖 Synopsis: Set up Git in personal laptops and connect it to personal GitHub repositories for individual accounts.
Step-by-step guide for students to install Git on Windows, set up SSH keys,
configure Git to use the correct key, and connect to a private GitHub repository.
1. Install Git for Windows
- Go to: https://git-scm.com/download/win
- Download and run the installer.
- Use default settings, but when asked for:
- “Choosing the default editor used by Git” → you can choose Notepad or Visual Studio Code.
- “Choosing HTTPS transport backend” → choose Use OpenSSH.
- Finish the installation.
To verify Git is installed: Open Git Bash (you can find it in the Start Menu), and type:
git --version
2. Configure Your Git Identity
In Git Bash, enter your name and email (use the same email as used on GitHub):
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
3. Generate SSH Keys for GitHub
In Git Bash, run:
ssh-keygen -t ed25519 -C "your@email.com" -f ~/.ssh/id_github
- When prompted for a passphrase, press Enter to leave it empty.
This creates two files:
~/.ssh/id_github
(private key)~/.ssh/id_github.pub
(public key)
4. Add the Public Key to Your GitHub Account
Log in to https://github.com
Go to Settings → SSH and GPG keys → New SSH key
Title: For example
My Windows Laptop
In Git Bash, run:
cat ~/.ssh/id_github.pub
Copy the entire output (starting with
ssh-ed25519
) and paste it into GitHub.Click Add SSH key
5. Create or Edit SSH Config File
To ensure Git uses the correct key when connecting to GitHub:
Open Git Bash
Run:
nano ~/.ssh/config
Add the following:
Host github.com HostName github.com User git IdentityFile ~/.ssh/id_github
Save and exit (
CTRL+O
, Enter, thenCTRL+X
)
6. Test SSH Connection
In Git Bash, run:
ssh -T git@github.com
You should see a message like:
Hi yourusername! You've successfully authenticated...
7. Create a Private GitHub Repository
Go to https://github.com and log in.
Click the “+” icon (top right) → “New repository”
Fill in:
Repository name:
your-repo-name
Visibility: Private
Leave all checkboxes unchecked:
- Add a README
- Add .gitignore
- Choose a license
Click Create repository
Click Code → Select SSH → Copy the link (e.g.,
git@github.com:yourusername/your-repo-name.git
)
8. Create or Open a Local Project in RStudio
In RStudio:
- Go to File → New Project → New Directory → Empty Project
- Name the folder and choose a location
- Click Create Project
Enable Git in the project:
- Tools → Project Options → Git/SVN → Check Enable version control interface for this project
In the RStudio Terminal (bottom pane), run:
git init
git remote add origin git@github.com:yourusername/your-repo-name.git
9. Make Initial Commit and Push to GitHub
- (Optional) Create a file locally, e.g.,
README.md
or.R
script. - Run the following in the Terminal:
git add .
git commit -m "Initial commit"
git branch -M main
git push -u origin main
You are Done!
You can now:
- Commit the changes to your local git repository;
- Push the local commit history to your GitHub repo:
git add .
git commit -m "your message"
git push