-
Notifications
You must be signed in to change notification settings - Fork 1
/
setting-up-git-and-github.qmd
396 lines (271 loc) · 12.1 KB
/
setting-up-git-and-github.qmd
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
---
title: Installing Git and Setting Up GitHub
---
Version control is a fundamental skill in modern software development and
data science. To address the challenges of code management, collaboration, and
backup, Git has emerged as the industry standard. Git is a distributed version
control system that tracks changes to your codebase, allowing you to work
efficiently and collaboratively.
This chapter will guide you through the process of setting up Git and GitHub on
your computer, regardless of your operating system. We'll explore not just the
how, but also the why behind each step, ensuring you have a solid foundation
for your development journey.
## Why Git?
Git solves several critical problems in software development:
- **History Tracking**: Every change to your code is recorded, allowing you to review or revert changes when needed.
- **Collaboration**: Multiple developers can work on the same project without conflicts.
- **Branching**: You can experiment with new features without affecting the main codebase.
- **Backup**: Your code is stored both locally and remotely, providing redundancy.
### Git vs. GitHub
Before we go further, let's clarify an important distinction:
- **Git** is the version control system you install on your computer
- **GitHub** is a web-based platform that hosts Git repositories and adds collaboration features
## Prerequisites
Before installing Git and setting up GitHub, ensure you have:
- Administrative access to your computer
- A stable internet connection
- Approximately 2GB of free disk space
- Basic familiarity with command-line operations
- A modern web browser for GitHub account creation
## Installing Git
The installation process varies by operating system. We'll cover each major
platform in detail. Choose the section that matches your system. Do not install
Git from unofficial sources to avoid security risks.
### Windows Installation
Windows users have several options for installing Git, but we recommend the
official Git for Windows installer for its reliability and included tools.
#### Step-by-Step Windows Installation
{{<video https://youtu.be/TmTjXuqNnhA >}}
1. **Download the Installer**
- Navigate to [git-scm.com/download/win](https://git-scm.com/download/win)
- The download should start automatically
- Choose the appropriate version (32-bit or 64-bit)
- If unsure, select the 64-bit version (most modern systems support and use it.)
2. **Run the Installer**
During installation, you'll encounter several configuration options. Here are
our recommended settings with explanations:
a. **Select Components**
```
✓ Windows Explorer integration
✓ Git Bash Here
✓ Git GUI Here
✓ Git LFS (Large File Support)
✓ Associate .git* configuration files with default text editor
✓ Associate .sh files to be run with Bash
```
b. **Choosing the default editor**
- Select your preferred editor (we recommend Visual Studio Code if installed)
- If unsure, choose Notepad
c. **Adjusting your PATH environment**
- Choose "Git from the command line and also from 3rd-party software"
- This allows you to use Git from both Git Bash and Windows Command Prompt
d. **Choosing HTTPS transport backend**
- Select "Use the native Windows Secure Channel library"
- This integrates better with Windows security features
e. **Configuring line ending conversions**
- Select "Checkout Windows-style, commit Unix-style line endings"
- This prevents issues when collaborating across different operating systems
3. **Verify Installation**
Open Git Bash or Command Prompt and type:
```bash
git --version
```
### macOS Installation
macOS offers multiple installation methods. We'll cover both the recommended
Xcode CLI approach and Homebrew. Please choose the one that suits your needs.
#### Using the Xcode Command Line Tools
We recommend using Xcode Command Line Tools method for macOS users as it
provides a stable, reliable, light-weight, and easy-to-maintain installation
of Git. This is because Xcode Command Line Tools are Apple supported and
updated regularly.
{{<video https://www.youtube.com/watch?v=Z01lzHNrSdU >}}
1. Opening `Terminal`
- Found under `Applications` -> `Utilities` -> `Terminal.app`;
- Or, by typing in "Spotlight" in the upper right-hand corner `Terminal`.
2. Once `Terminal` is open type:
```bash
sudo xcode-select --install
```
3. This will trigger an installation pop-up. Please follow the installer prompts.
4. To verify the success of the installation, type into `Terminal`:
```bash
git --version
```
#### Using Homebrew
Homebrew is a package manager for macOS that simplifies the installation of
software. If you continue on your data science journey, you'll find Homebrew
useful for installing other tools and libraries. Thus, we're including it here
as an alternative installation method. That said, Xcode Command Line Tools
is automatically installed through a GUI-free method
when you run the Homebrew installation command.
If you already have Homebrew installed, you can skip the first step.
1. **Install Homebrew**
Open Terminal and run:
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
Follow the prompts to complete installation.
2. **Install Git**
```bash
brew install git
```
### Linux Installation
The installation process varies by distribution. We'll cover the most popular ones.
If your distribution is not listed, refer to the [official Git documentation](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).
#### Ubuntu/Debian
In Ubuntu and Debian-based systems, you can install Git using `apt`.
Open Terminal and run:
```bash
sudo apt update
sudo apt install git-all
```
#### Fedora
In Fedora, you can install Git using `dnf`. Open Terminal and run:
```bash
sudo dnf install git-all
```
## Configuring Git
After installation, you need to configure Git with your identity.
This information will be attached to your commits.
### Basic Configuration
Run the following commands in Terminal to set your name and email:
```bash
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
```
Replace `"Your Name"` and `"[email protected]"` with your actual name and email address.
:::{.callout-important}
Do not use a fake name or email. Your identity is crucial for collaboration and accountability.
:::
:::{.panel-tabset}
### macOS Video Tutorial
{{<video https://www.youtube.com/watch?v=CnKpOwAFeIE >}}
### Windows Video Tutorial
{{<video https://www.youtube.com/watch?v=jEacLROiTNU >}}
:::
### Advanced Configuration
We recommend setting up a few additional configurations to enhance your Git experience.
You do not need to set these up immediately, but they can be helpful as you
become more comfortable with Git.
We recommend the following configurations:
```bash
# Set default branch name to 'main'
git config --global init.defaultBranch main
# Enable colorful git output
git config --global color.ui auto
# Configure line ending behavior
git config --global core.autocrlf input # On Unix/Mac
git config --global core.autocrlf true # On Windows
```
## Setting Up GitHub
GitHub extends Git's capabilities with a web-based interface and collaboration features.
To use GitHub, you need to create an account and set up SSH authentication.
We'll guide you through both processes.
### Creating a GitHub Account
First, create a GitHub account if you don't have one already. You can sign up for free
by following these steps:
1. Visit [github.com](https://github.com)
2. Click "Sign up"
3. Follow the registration process
4. Choose the free plan for personal use
5. Verify your email address
- We recommend using your `.edu` email for student benefits
Need more help? Check out GitHub's [Creating an account on GitHub](https://docs.github.com/en/get-started/start-your-journey/creating-an-account-on-github) support page.
### Student Benefits
GitHub offers free access to its Pro features for students. To activate this:
1. Go to [GitHub Education](https://education.github.com)
2. Click ["Join GitHub Education"](https://education.github.com/discount_requests/application?type=student)
3. Follow the instructions to verify your student status
You will need to provide proof of enrollment, such as a school email and ID.
GitHub will also check your computer's location relative to your school's location.
Thus, we recommend using the school network or VPN if studying abroad.
With a verified student account, you can access
- [GitHub Copilot](https://github.com/features/copilot): AI-powered code completion;
- [GitHub Actions](https://github.com/features/actions): Extended Automated workflows for CI/CD;
- [GitHub Codespace](https://github.com/features/codespaces): Cloud-based development environment;
- [GitHub Pages](https://pages.github.com/): Free hosting for static websites;
And [more](https://education.github.com/pack)!
You will need to re-verify your student status every other year.
### Setting Up SSH Authentication
SSH keys provide a secure way to connect to GitHub without entering your password repeatedly.
Previously, we could use our GitHub username and password to authentication over SSH.
As of August 13, 2021, GitHub removed that option in favor of SSH keys or personal access tokens.
We'll guide you through setting up SSH keys for secure, password-free authentication.
If you already have an SSH key, you can skip the key generation steps.
Moreover, you may want to consult the official GitHub documentation on
[Generating a new SSH key and adding it to the ssh-agent](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).
These instructions can change depending on operating system and advances in
generating SSH keys.
#### Generating SSH Keys
We can generate SSH keys using the `ssh-keygen` command.
1. **Generate SSH Key**
```bash
ssh-keygen -t ed25519 -C "[email protected]"
```
When prompted:
- Press Enter to accept the default file location
- Enter a secure passphrase (recommended)
2. **Start SSH Agent**
```bash
eval "$(ssh-agent -s)"
```
3. **Add Your SSH Key**
:::{.panel-tabset}
### For Windows/Linux
```bash
ssh-add ~/.ssh/id_ed25519
```
### For macOS:
```bash
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
```
:::
4. **Add Key to GitHub**
- Copy your public key:
```bash
cat ~/.ssh/id_ed25519.pub
```
- Go to GitHub → [Settings](https://github.com/settings/) → [SSH and GPG keys](https://github.com/settings/keys)
- Click ["New SSH key"](https://github.com/settings/ssh/new)
- Paste your key and save
- We recommend giving your key a descriptive name especially if you have
multiple keys (e.g., "Work Laptop", "Personal Desktop").
5. **Verify Connection**
```bash
ssh -T [email protected]
```
## Summary
You now have a fully configured Git installation and GitHub account. This setup
will serve as the foundation for all your version control needs. In the next
chapter, we'll explore basic Git commands and workflows in detail.
### Key Takeaways
- Git is a powerful version control system that works across all major platforms
- GitHub provides a centralized location for storing and sharing code
- SSH keys enable secure, password-free authentication
- Proper configuration is crucial for a smooth Git experience
## Additional Resources
- [Pro Git Book](https://git-scm.com/book/en/v2)
- [GitHub Guides](https://guides.github.com)
## Troubleshooting
If you encounter issues during installation or configuration, refer to the following
common problems and solutions. If your issue persists, please let us know on
our discussion forums or on the GitHub repository's issue tracker.
### SSH Issues
If you encounter SSH connection problems:
1. Verify SSH agent is running:
```bash
eval "$(ssh-agent -s)"
```
2. Check if your key is added:
```bash
ssh-add -l
```
3. Verify GitHub can read your key:
```bash
ssh -vT [email protected]
```
### Git Configuration Issues
To view your current Git configuration:
```bash
git config --list
```