Skip to content

Commit

Permalink
Feat/exercise 1 (#1)
Browse files Browse the repository at this point in the history
* Starting exercise_1

* exercise_1 guide

* Split into multiple files

* fix: renamed files with convention

* feat: refactored images and best practices page

---------

Co-authored-by: shynxe <[email protected]>
  • Loading branch information
Aurelian-Iancu and shynxe authored Nov 12, 2023
1 parent 27b6930 commit d263ef5
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 3 deletions.
4 changes: 4 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Summary

- [Chapter 1](./src/chapter-1.md)
- [Exercise 1](./src/exercise-1/exercise-1.md)
3 changes: 0 additions & 3 deletions src/SUMMARY.md

This file was deleted.

File renamed without changes.
37 changes: 37 additions & 0 deletions src/exercise-1/add-ssh-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Adding a new SSH key to your GitHub account

1. Copy the SSH public key to your clipboard. Use the following command, replacing the filename:

```bash
$ clip < ~/.ssh/{filename}.pub
```

<details>

- On Windows Subsystem for Linux (WSL), you can use `clip.exe`. Otherwise, locate the hidden `.ssh` folder and copy the key manually.
- On newer versions of Windows with PowerShell, you may use:
```bash
$ cat ~/.ssh/{filename}.pub | clip
```

</details>

2. In the upper-right corner of any GitHub page, click your profile photo, then click **Settings**.

<img src="images/settingsLocation.png" alt="Setting Location" width="200"/>

3. In the "Access" section of the sidebar, click **SSH and GPG keys**.

<img src="images/SSHandGPGkeysLocation.png" alt="Setting Location" width="200"/>

4. Click **New SSH key** or **Add SSH key**.

5. In the "Title" field, add a descriptive label for the new key (e.g., "Personal laptop").

6. Select the type of key: either authentication or signing.

7. In the "Key" field, paste your public key.

8. Click **Add SSH key**.

9. If prompted, confirm access to your GitHub account.
26 changes: 26 additions & 0 deletions src/exercise-1/cheatsheet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Cheatsheet

Here's a reference list of commonly used Git commands:

### Commands related to a remote repository:

- `git clone [email protected]:USER-NAME/REPOSITORY-NAME.git`
- `git push` or `git push origin main`

### Commands related to the workflow:

- `git add .`
- `git commit -m "A message describing the changes"`

### Commands related to checking status or log history:

- `git status`
- `git log`

The basic Git syntax is `program | action | destination`.

For example:

- `git add .` is read as `git | add | .`, where the period represents everything in the current directory.
- `git commit -m "message"` is read as `git | commit -m | "message"`.
- `git status` is read as `git | status | (no destination)`.
23 changes: 23 additions & 0 deletions src/exercise-1/create-repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Exercise

## Before You Start

1. Ensure you have Git version 2.28 or later. Check your version with: `git --version`
2. Set your local default Git branch to `main` by running: `git config --global init.defaultBranch main`

## Create the Repository on GitHub

3. Create a GitHub account if you haven't already.
4. Click the "+" button on GitHub to create a new repository.
5. Name it "git-test," check "Add a README file," and click "Create repository."

## Clone the Repository to Your Local Machine

6. Click the green "Code" button on your GitHub repository.
7. Select the SSH option, copy the displayed URL.
8. Open your terminal and create a directory named "repos" in your home folder: `mkdir ~/repos`
9. Move into the new directory: `cd ~/repos`
10. Clone the repository using the copied URL: `git clone [email protected]:USER-NAME/REPOSITORY-NAME.git`
11. Verify the connection: `cd git_test` and `git remote -v`

You've successfully connected your GitHub repository to your local machine. The remote connection is named "origin," a default convention.
21 changes: 21 additions & 0 deletions src/exercise-1/exercise-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Exercise 1

Welcome to the Git Essentials first exercise! This exercise is designed to guide you through essential Git processes using various operating systems and SSH keys. Below is a breakdown of the tasks you'll explore:

- [Generate SSH Keys in Windows](./generate-ssh-windows.md)
- [Generate SSH Keys in Linux](./generate-ssh-linux.md)
- [Add SSH Key](./add-ssh-key.md)
- [Create Repository](./create-repository.md)
- [Use Git Workflow](./use-git-workflow.md)
- [Modify Files](./git-modify-files.md)
- [Push work to Github](./push-work-to-github.md)
- [Cheatsheet](./cheatsheet.md)
- [Git best practices](./git-best-practices.md)

## Understanding SSH Keys

SSH keys are crucial for secure communication between your computer and remote servers. They act as a secure way to authenticate and establish secure connections, ensuring that data exchanged between systems is encrypted and protected from unauthorized access.

These keys provide a way to verify your identity without a password, making the authentication process more secure and convenient. They consist of a public key, which you share with others or services, and a private key, which remains exclusively on your machine.

GitHub strongly encourages SSH keys due to their security benefits and the limitations of HTTPS. While HTTPS is still an option, it can be less convenient due to frequent password prompts. SSH keys, on the other hand, offer a more secure and seamless way to authenticate without the need for constant password entry. Additionally, GitHub has set rate limits for unauthenticated use of their API, making SSH keys almost essential for smoother and more efficient interactions with their services.
15 changes: 15 additions & 0 deletions src/exercise-1/generate-ssh-linux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generating SSH Keys in Linux

## Generating a new SSH key

1. Open Git Bash.
2. Paste the following command, replacing the email with your GitHub email:
```bash
ssh-keygen -t ed25519 -C "[email protected]"
```
If your system doesn't support Ed25519, use:
```bash
ssh-keygen -t rsa -b 4096 -C "[email protected]"
```
3. Press Enter to accept the default file location.
4. Type a secure passphrase when prompted.
23 changes: 23 additions & 0 deletions src/exercise-1/generate-ssh-windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generating SSH Keys in Windows 10

## Generate SSH Key with OpenSSH Client

### Step 1: Verify OpenSSH Client Installation

1. Open Settings, click on Apps.
2. Under Optional Features, check if OpenSSH Client is listed.
3. If not listed, add it by clicking "Add a feature" and selecting OpenSSH Client.

### Step 2: Open Command Prompt

1. Press the Windows key.
2. Type `cmd`.
3. Right-click Command Prompt and select "Run as Administrator."

### Step 3: Use OpenSSH to Generate SSH Key Pair

1. In the command prompt, type: `ssh-keygen`
2. Press Enter to use the default location.
3. Enter a passphrase or press Enter to skip.
4. The system will generate keys; locate them in `C:\Users\your_username/.ssh`.
5. Public key: `id_rsa.pub`, Private key: `id_rsa`
34 changes: 34 additions & 0 deletions src/exercise-1/git-best-practices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Git Best Practices

Using Git effectively can greatly enhance your development workflow. Here are some valuable best practices to consider:

## Collaborative and Independent Work

Git serves you well whether you're collaborating with a team or working solo. It's versatile and adapts to different scenarios.

## Atomic Commits

**Atomic commits** are a fundamental concept in Git. They involve making small, focused commits that encapsulate a single change. This practice makes it easier to manage your project and maintain a clear history. For example, if you're working on a web application and you fix a bug related to user authentication, create a separate commit for it:

```
- Fix user authentication bug
```

## Meaningful Commit Messages

A well-crafted commit message is a crucial aspect of Git best practices. It should provide a clear and concise summary of your changes. Additionally, include a more detailed explanation when necessary. Here's an example of a meaningful commit message:

```
- Implement new feature for user profile
- This commit adds a user profile page with user details and profile picture functionality. It addresses issue #123.
```

## Customizing Git Commit Message Editor

Git allows you to customize your commit message editor. If you prefer using Visual Studio Code, you can set it as your default editor for Git commit messages. To do this, run the following command:

```
git config --global core.editor "code --wait"
```

This command configures Git to use Visual Studio Code as the default commit message editor.
56 changes: 56 additions & 0 deletions src/exercise-1/git-modify-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Exercise

## Modify a File or Two

1. Open `README.md` in your text editor of choice. In this example, we will open the directory in Visual Studio Code by using the command `code .` inside your repository.

```bash
# Edit README using text editor
code .
```

<details>
**Note for MacOS users:** If your terminal reads “command not found: code,” you must head back to [Command Line Basics](#) and follow the instructions provided to allow this command to work.
</details>

2. Add “Hello Odin!” to line 3 of `README.md` and save the file with `Ctrl + S` (Mac: `Cmd + S`).

**Edit README using text editor**

3. Go back to your terminal, or if you’re using Visual Studio Code, you can open the built-in terminal by pressing `Ctrl + \` (backtick). Then type `git status`. You’ll notice that `README.md` is now shown as not staged or committed.

```bash
# Check repo status again using CLI
git status
```

4. Add `README.md` to the staging area with `git add README.md`.

```bash
# Stage README changes and check repo status again using CLI
git add README.md
```

**Can you guess what `git status` will output now?** `README.md` will be displayed in green text. That means `README.md` has been added to the staging area. The file `hello_world.txt` will not show up because it has not been modified since it was committed.

5. Open `hello_world.txt`, add some text to it, save it, and stage it. You can use `git add .` to add all files in the current directory and all subsequent directories to the staging area. Then, type `git status` once more, and everything should now be in the staging area.

```bash
# Stage all other files in repo and check repo status again using CLI
git add .
```

6. Finally, let’s commit all of the files that are in the staging area and add a descriptive commit message: `git commit -m "Edit README.md and hello_world.txt"`. Then, type `git status` once again, which will output “nothing to commit.”

```bash
# Commit repo changes again and check repo status again using CLI
git commit -m "Edit README.md and hello_world.txt"
git status
```

7. Take one last look at your commit history by typing `git log`. You should now see three entries.

```bash
# Check repo commit history using CLI
git log
```
Binary file added src/exercise-1/images/SSHandGPGkeysLocation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/exercise-1/images/settingsLocation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions src/exercise-1/push-work-to-github.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Exercise

## Push Your Work to GitHub

1. Finally, let’s upload your work to the GitHub repository you created at the start of this tutorial.

```bash
# Push changes to remote using CLI
git push
```

To be more specific, you can type `git push origin main`. Since you are not dealing with another branch (other than `main`) or a different remote, you can leave it as `git push` to save a few keystrokes.
<details>
**Note:** If you receive a message that says “Support for password authentication was removed on August 13, 2021. Please use a personal access token instead,” at this point, you have followed the steps incorrectly and cloned with HTTPS, not SSH.
</details>

2. Type `git status` one final time. It should output “Your branch is up to date with ‘origin/main’. Nothing to commit, working tree clean”.

```bash
# Check repo status again to confirm local repo is up to date with remote using CLI
git status
```

3. When you reload the repository on GitHub, you should see the `README.md` and `hello_world.txt` files that you just pushed there from your local machine.
48 changes: 48 additions & 0 deletions src/exercise-1/use-git-workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Exercise

## Use the Git Workflow

1. Create a new file in the `git_test` folder called "hello_world.txt" with the command: `touch hello_world.txt`.

```bash
# Create hello_world.txt using CLI
touch hello_world.txt
```

2. Check the status of your repository by typing `git status` in your terminal. The output shows that `hello_world.txt` is in red, indicating it is not staged.

```bash
# Check the status of the repo using CLI
git status
```

3. Add `hello_world.txt` to the staging area using the command: `git add hello_world.txt`. This prepares the file for the commit.

```bash
# Stage hello_world and check repo status again using CLI
git add hello_world.txt
```

4. Type `git status` again. The output now shows `hello_world.txt` in green, indicating it is in the staging area.

```bash
# Check repo status again using CLI
git status
```

5. Make a commit with the message "Add hello_world.txt" using the command: `git commit -m "Add hello_world.txt"`. Then, check the status once more. The output should indicate "nothing to commit, working tree clean."

```bash
# Commit hello_world and check repo status again using CLI
git commit -m "Add hello_world.txt"
git status
```

6. Check the commit history using git log:

```bash
# Check repo commit history using CLI
git log
```

7. The message "Your branch is ahead of 'origin/main' by 1 commit" indicates that your local branch has one more commit than the remote repository. This will be resolved when you push your changes.

0 comments on commit d263ef5

Please sign in to comment.