-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek10.qmd
More file actions
186 lines (122 loc) · 3.8 KB
/
week10.qmd
File metadata and controls
186 lines (122 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
---
title: "Week 10 | Setup Git in personal laptop"
---
::: {.callout-note}
## Class Details
📅 **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
1. Go to: [https://git-scm.com/download/win](https://git-scm.com/download/win)
2. Download and run the installer.
3. 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*.
4. 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
1. Log in to [https://github.com](https://github.com)
2. Go to **Settings** → **SSH and GPG keys** → **New SSH key**
3. Title: For example `My Windows Laptop`
4. In Git Bash, run:
```
cat ~/.ssh/id_github.pub
```
Copy the entire output (starting with `ssh-ed25519`) and paste it into GitHub.
5. Click **Add SSH key**
---
### 5. Create or Edit SSH Config File
To ensure Git uses the correct key when connecting to GitHub:
1. Open Git Bash
2. Run:
```
nano ~/.ssh/config
```
3. Add the following:
```
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_github
```
4. Save and exit (`CTRL+O`, Enter, then `CTRL+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
1. Go to [https://github.com](https://github.com) and log in.
2. Click the **"+"** icon (top right) → **"New repository"**
3. Fill in:
* **Repository name**: `your-repo-name`
* **Visibility**: *Private*
* Leave all checkboxes **unchecked**:
* Add a README
* Add .gitignore
* Choose a license
4. Click **Create repository**
5. 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
1. In RStudio:
* Go to **File → New Project → New Directory → Empty Project**
* Name the folder and choose a location
* Click **Create Project**
2. Enable Git in the project:
* **Tools → Project Options → Git/SVN** → Check *Enable version control interface for this project*
3. 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
1. (Optional) Create a file locally, e.g., `README.md` or `.R` script.
2. 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
```