|
| 1 | +<!-- TITLE: Git Started With Git --> |
| 2 | +<!-- SUBTITLE: Cheat Sheet for First Time git Users --> |
| 3 | + |
| 4 | +# Source Control: How I Learned to Stop Worrying, and Love Git |
| 5 | + |
| 6 | +## Objectives |
| 7 | + |
| 8 | +This document will provide a guide for the following topics: |
| 9 | + |
| 10 | +* [Intro to Git: Warmup Activity (15 Minutes)](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#intro-to-git-warmup-activity-15-minutes) |
| 11 | +* [Installing Git](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#installing-git) |
| 12 | + * [macOS](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#macos) |
| 13 | + * [Windows 10](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#windows-10) |
| 14 | + * [Linux](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#linux) |
| 15 | +* [Configuring Git](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#configuring-git) |
| 16 | +* [Verifying Your Installation](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#verifying-your-installation) |
| 17 | +* [Generating and Configuring SSH Keys](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#generating-and-configuring-ssh-keys) |
| 18 | +* [Cloning a Remote Repository to Your Local Machine](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#cloning-a-remote-repository-to-your-local-machine) |
| 19 | +* [Updating Your Local Repository When New Content is Available](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#updating-your-local-repository-when-new-content-is-available) |
| 20 | +* [Adding, Committing, and Pushing Local Changes to Remote Repositories](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#adding-committing-and-pushing-local-changes-to-remote-repositories) |
| 21 | +* [More Practice/Additional Educational Resources](https://github.com/outputs-io/dataviz-docs/blob/master/git/README.md#more-practiceadditional-educational-resources) |
| 22 | + |
| 23 | +## Intro to Git: Warmup Activity (15 Minutes) |
| 24 | + |
| 25 | +Before setting Git up on your development machine, consider attempting the 'Try Git' challenge! |
| 26 | +This will allow you to get a feel for using git in a guided setting, before you run the commands on your machine. |
| 27 | + |
| 28 | +**Highly recommended: [Interactive: Learn Git Online](https://try.github.io/levels/1/challenges/1)** |
| 29 | + |
| 30 | +## Installing Git |
| 31 | + |
| 32 | +**‼️ IMPORTANT: $ denotes a command that must be pasted into `Terminal`/`Git Bash`.** |
| 33 | + |
| 34 | +### macOS |
| 35 | + |
| 36 | +1. Hold down ⌘ and press the Spacebar to invoke Spotlight. |
| 37 | +1. Type `Terminal.app`. |
| 38 | +1. In `Terminal.app`, run the following command to install [Homebrew](https://brew.sh): |
| 39 | + |
| 40 | + ```bash |
| 41 | + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
| 42 | + ``` |
| 43 | + |
| 44 | +1. Once Homebrew is installed, run `brew install git` to install the latest version of git. |
| 45 | + |
| 46 | +### Windows 10 |
| 47 | + |
| 48 | +1. Navigate to [Git: Download Windows Package](https://git-scm.com/download/win) in your browser. |
| 49 | +1. If prompted, save the file. |
| 50 | +1. Navigate to the directory you saved the file in, and double-click to launch the installer. |
| 51 | +1. Hit **Next >** on each screen to select the default settings and complete the installation. |
| 52 | + |
| 53 | +### Linux |
| 54 | + |
| 55 | +#### Debian/Ubuntu: |
| 56 | + |
| 57 | +1. Install Git via `apt` by running: |
| 58 | + |
| 59 | + ```bash |
| 60 | + $ sudo apt-get update |
| 61 | + $ sudo apt-get install git-all |
| 62 | + ``` |
| 63 | + |
| 64 | +#### Red Hat/CentOS: |
| 65 | + |
| 66 | +1. Install Git via `dnf` by running: |
| 67 | + |
| 68 | + ```bash |
| 69 | + $ sudo dnf -y update |
| 70 | + $ sudo dnf install -y git |
| 71 | + ``` |
| 72 | + |
| 73 | +## Verifying Your Installation |
| 74 | + |
| 75 | +1. To verify git is installed correctly, open `Terminal` (macOS/Linux) or `Git Bash` (Windows). |
| 76 | + |
| 77 | +1. Run `git --version` within the new [shell](<https://en.wikipedia.org/wiki/Shell_(computing)>): |
| 78 | + ```bash |
| 79 | + $ git --version |
| 80 | + git version 2.15.1 |
| 81 | + ``` |
| 82 | + |
| 83 | +## Configuring Git |
| 84 | + |
| 85 | +1. Configure your global username and email address. |
| 86 | + |
| 87 | +**‼️ IMPORTANT: If you skip this step, Git will produce a warning each time you push to a remote branch.** |
| 88 | + |
| 89 | + ```bash |
| 90 | + $ git config --global user.name "Dani Roxberry" |
| 91 | + $ git config --global user.email "[email protected]" |
| 92 | + ``` |
| 93 | + |
| 94 | +1. Optional. Configure additional, helpful settings: |
| 95 | + |
| 96 | + * [**macOS/Linux**] Set the default text editor to VSCode: |
| 97 | + |
| 98 | + ```bash |
| 99 | + $ git config --global core.editor code |
| 100 | + ``` |
| 101 | + |
| 102 | + * [**Windows**] On a Windows system, if you want to use a different text editor, you must specify the full path to its executable file: |
| 103 | + |
| 104 | + ```bash |
| 105 | + $ git config --global core.editor "<FULL PATH TO VSCODE EXE IN QUOTES>" |
| 106 | + ``` |
| 107 | + |
| 108 | +1. Double-check your settings: |
| 109 | + |
| 110 | + ```bash |
| 111 | + $ git config --list |
| 112 | +
|
| 113 | + credential.helper=osxkeychain |
| 114 | + user.name=Dani Roxberry |
| 115 | + |
| 116 | + url.ssh://[email protected]/.insteadof=https://github.com/ |
| 117 | + mergetool.keepbackup=false |
| 118 | + core.excludesfile=/Users/dani/.gitignore_global |
| 119 | + core.editor=code |
| 120 | + filter.lfs.required=true |
| 121 | + filter.lfs.clean=git-lfs clean -- %f |
| 122 | + filter.lfs.smudge=git-lfs smudge -- %f |
| 123 | + filter.lfs.process=git-lfs filter-process |
| 124 | + ``` |
| 125 | + |
| 126 | +## Generating and Configuring SSH Keys |
| 127 | + |
| 128 | +1. Run the following commands. |
| 129 | + |
| 130 | + **‼️ IMPORTANT: DO NOT ENTER A PASSWORD WHEN PROMPTED**. Just hit enter. |
| 131 | + |
| 132 | + ```bash |
| 133 | + $ ssh-keygen -t rsa -C "[email protected]" -b 4096 |
| 134 | + $ cat ~/.ssh/id_rsa.pub |
| 135 | +
|
| 136 | + ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC+SJSGSCeSeLnOg543Hyqh3OcAENvugks8ygkoOkEA4g652gK0ES7CjjpBy4GS/XnaUWiD9iaoE4soE8dqhe/psCoiU+QxGmkjNapLtQAOu1W2v/SEh3Jao+rtfop0S+Ak96fiOVgUgupFAN1FXV1iYdpwyk7rR3Kv/T2M9Ce06Bk5KupdgNzF7Eg/tmFx8H2yVmeQ2J3MWM948ZvWmbBwtbcDRQ6ZtnXSoEof1Wg8agzyisq0Yoi3rXqAIxr1Hevs4g79Lrf65548yTfqZqyljSFA/h4VntXsZYKIWoXti5uPstrwRF6oaH8dm1l74jLAKC/XlqnsqVkRWn/Updj+x8g3+EdtFiWpUwEIMWWDbjPk0HHTfOS06716Hcji0hg4Kfipe03QjhD8Vqp/snaYCb8R3OSZOK1H3Zj9n1JgHhOoFYzk0gstV9DGRmrm2ywrQh3Q7fs23pzrZARGBhRHwk5XfFQl85D7oJffBbfpqjDdyzcHYOAo3mlDfwkfl1nHxynWrwCk+0KKD0zLVsqtkSVlNfQv2JqSSc6ox6vktO7RWKg5/T0b9r0fnNcYfGBVnoJDulJPJr7ynSUDRi2hX5WpMDomylUahVYN/VlAZBwvuWdOM0h3ZUsQEPjauN0k+mY3nQVTIa0hWl1vszTddcxLZKK5mJsvlnL7HMBQxQ== [email protected] |
| 137 | + ``` |
| 138 | + |
| 139 | +1. With your mouse, highlight the entire [public key](https://en.wikipedia.org/wiki/Public-key_cryptography), beginning with `ssh-rsa` and ending with your email address. Copy the highlighted public key to the clipboard. |
| 140 | + |
| 141 | +1. Add the key to [**GitLab**](http://ucb.bootcampcontent.com/profile/keys): |
| 142 | + |
| 143 | + * Click the above link and paste your key in the 'Key' section and give it a relevant 'Title'. Use an identifiable title like 'Work Laptop - Windows 7' or 'Home MacBook Pro 15'. |
| 144 | + |
| 145 | + * **Make sure you copied the entire key starting with `ssh-rsa` and ending with your email.** |
| 146 | + |
| 147 | + * Test your setup by running `ssh -T [email protected]` (replacing `example.com` with your GitLab domain) and verifying that you receive a `Welcome to GitLab` message. |
| 148 | + |
| 149 | + * Test using our Class Repository with this command: `ssh -T [email protected]` |
| 150 | + |
| 151 | + * You should receive the following output: |
| 152 | + |
| 153 | + ```bash |
| 154 | + |
| 155 | +
|
| 156 | + Welcome to GitLab, Dani Roxberry! |
| 157 | + ``` |
| 158 | + |
| 159 | +1. Add the key to [**GitHub**](https://github.com/settings/ssh/new): |
| 160 | + |
| 161 | + * Click the above link and paste your key in the 'Key' section and give it a relevant 'Title'. Use an identifiable title like 'Work Laptop - Windows 7' or 'Home MacBook Pro 15'. |
| 162 | + |
| 163 | + * **Make sure you copied the entire key starting with `ssh-rsa` and ending with your email.** |
| 164 | + |
| 165 | + * Test your setup by running `ssh -T [email protected]`: |
| 166 | + |
| 167 | + ```bash |
| 168 | + |
| 169 | +
|
| 170 | + Hi droxey! You've successfully authenticated, but GitHub does not provide shell access. |
| 171 | + ``` |
| 172 | +
|
| 173 | +## Cloning a Remote Repository to Your Local Machine |
| 174 | +
|
| 175 | +```bash |
| 176 | +$ git clone [email protected]:UCB-Coding-Bootcamp/UCBSAN201802DATA3-Class-Repository-DATA.git |
| 177 | +
|
| 178 | +Cloning into 'UCBSAN201802DATA3-Class-Repository-DATA'... |
| 179 | +remote: Counting objects: 110, done. |
| 180 | +remote: Compressing objects: 100% (96/96), done. |
| 181 | +remote: Total 110 (delta 10), reused 0 (delta 0) |
| 182 | +Receiving objects: 100% (110/110), 50.72 MiB | 2.69 MiB/s, done. |
| 183 | +Resolving deltas: 100% (10/10), done. |
| 184 | +``` |
| 185 | +
|
| 186 | +## Updating Your Local Repository When New Content is Available |
| 187 | +
|
| 188 | +```bash |
| 189 | +$ git pull origin master |
| 190 | +``` |
| 191 | +
|
| 192 | +## Adding, Committing, and Pushing Local Changes to Remote Repositories |
| 193 | +
|
| 194 | +```bash |
| 195 | +$ cd ~/dev/repos/my-new-repo |
| 196 | +$ git add . |
| 197 | +$ git commit -m "A good, descriptive commit message." |
| 198 | +$ git push origin master |
| 199 | +``` |
| 200 | +
|
| 201 | +## Get Advanced with Git |
| 202 | +
|
| 203 | +`COMING SOON!` |
| 204 | +
|
| 205 | +## More Practice/Additional Educational Resources |
| 206 | +
|
| 207 | +### Fundamentals |
| 208 | +
|
| 209 | +* [Getting Started: Git Overview](https://git-scm.com/book/en/v2/Getting-Started-Git-Basics) |
| 210 | +
|
| 211 | +### eBooks |
| 212 | +
|
| 213 | +* [Pro Git: Free eBook (HTML/PDF/EPUB/MOBI)](https://git-scm.com/book/en/v2) |
| 214 | +
|
| 215 | +### Videos |
| 216 | +
|
| 217 | +Quick overview of Git in video format. Each video is approximately 5 minutes long. |
| 218 | +
|
| 219 | +* [Git Basics: Episode 1 - What is Version Control? (VIDEO)](https://git-scm.com/video/what-is-version-control) |
| 220 | +* [Git Basics: Episode 2 - What is Git? (VIDEO)](https://git-scm.com/video/what-is-git) |
| 221 | +* [Git Basics: Episode 3 - Get Going with Git (VIDEO)](https://git-scm.com/video/get-going) |
| 222 | +* [Git Basics: Episode 4 - Quick Wins with Git (VIDEO)](https://git-scm.com/video/quick-wins) |
| 223 | +
|
| 224 | +### GitHub |
| 225 | +
|
| 226 | +* [Cheat Sheet (PDF)](https://services.github.com/on-demand/downloads/github-git-cheat-sheet.pdf) |
| 227 | + * Git is the open source distributed version control system that facilitates GitHub activities on your laptop or desktop. This cheat sheet summarizes commonly used Git command line instructions for quick reference |
| 228 | +
|
| 229 | +### GUIs |
| 230 | +
|
| 231 | +#### Free |
| 232 | +
|
| 233 | +* [GitHub Desktop](https://desktop.github.com/) |
| 234 | +
|
| 235 | + * macOS / Windows: A desktop, GUI based Git and GitHub client. |
| 236 | +
|
| 237 | +* [GitKraken](https//www.gitkraken.com) |
| 238 | +
|
| 239 | + * macOS / Windows / Linux: The legendary Git GUI client. |
| 240 | +
|
| 241 | +* [VSCode: Version Control](https://code.visualstudio.com/docs/editor/versioncontrol) |
| 242 | + * Handy documentation for the default Git integration that ships with VSCode. |
| 243 | +
|
| 244 | +#### Paid |
| 245 | +
|
| 246 | +* [Tower 2](https://www.git-tower.com/mac/) |
| 247 | + * macOS / Windows: Version control with Git made easy in a beautiful, efficient, and powerful app. |
| 248 | +
|
| 249 | +### Repositories of Note |
| 250 | +
|
| 251 | +* [git/git](https://github.com/git/git) |
| 252 | + * The Git source code on GitHub |
0 commit comments