Commit 9f1b38a5 authored by Tomas Tomecek's avatar Tomas Tomecek
Browse files

add labs 1 2 3

parent 2f5e2bb8
Loading
Loading
Loading
Loading

labs/lab1.md

0 → 100644
+36 −0
Original line number Diff line number Diff line
# Lab 1

## Together

* man git

* Generate SSH key and upload the pubkey to gitlab.com (`ssh-keygen -b 4096`)

* git config (--global --system --local)

* git init

* `git clone` this repo (explain https/ssh)

* git remote (only origin, upstream next time)

* Try pushing to https:// remote

* git add mv rm

* git status


## Exercise

1. Generate your SSH key and add the public key to your github.com account.

2. Configure Git with your user name and email.

3. Initialize a new Git repository on your local machine.

4. Clone a remote repository using both HTTPS and SSH protocols.

5. Create, move, and remove files within the repository.

6. Check the status of your repository and see the changes you've made.

labs/lab1.solution.md

0 → 100644
+131 −0
Original line number Diff line number Diff line
# Lab 1

## Solution

### Step 1: Generate SSH Key and Upload Pubkey

SSH keys provide a secure and convenient way to authenticate with Git repositories. They eliminate the need to enter passwords each time you interact with a remote repository, making the process more efficient and secure.

Open your terminal or command prompt and run the following command:

```bash
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
```

This command will generate an RSA key pair with a 4096-bit key size, and you'll be prompted to save the key in a specific location (e.g., `~/.ssh/id_rsa`) and set a passphrase (optional but recommended for added security).

Run the following command to print your public key:

```bash
cat ~/.ssh/id_rsa.pub
```

Copy the entire output, which represents your SSH public key, to the clipboard.

- Go to your git-hosting platform (gitforge)
- Find "SSH Keys" section in the settings.
- Paste your SSH public key into the "Key" field.

### Step 2: Configure Git

Configuring Git with your user name and email is essential because Git uses this information to identify you as the author of commits.

Git will not work without this: you won't be able to commit!

In your terminal or command prompt, run the following commands with your own information:

```bash
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
```

It's useful to see the current configuration:
```bash
git config -l
```

### Step 3: Initialize a Git Repository

A Git repository is a directory that contains all the necessary files and metadata to track changes in your project. It allows you to version control your project and collaborate with others effectively.

Create a new directory for your project, navigate into it, and run the following command:

```bash
git init
```

This will initialize an empty Git repository in your project directory.

### Step 4: Clone a Remote Repository

Cloning via SSH is preferred over HTTPS because it uses your SSH key for authentication, making the process more secure and convenient.

In your terminal or command prompt, run the following command:

```bash
git clone git@gitlab.com:redhat/research/mastering-git.git
```

### Step 5: Managing Remotes

Remotes are references to other repositories, usually the ones on remote servers like GitLab, GitHub, or Bitbucket. They allow you to collaborate with others by fetching, pulling, and pushing changes.

To list the remote repositories associated with your local repository, run:

```bash
git remote -v
```

To add a new remote (e.g., origin) to your local repository, use the following command:

```bash
git remote add origin <remote_url>
```

To remove a remote (e.g., origin), use the following command:

```bash
git remote remove origin
```

### Step 6: Basic Git Operations

In your terminal or command prompt, navigate to your local repository, and run:

```bash
git status
```

This will show you the current state of your repository, including the modified, staged, and untracked files.

To stage changes for the next commit, use the following command:

```bash
git add <file1> <file2> ... <fileN>    # To stage specific files
git add .                              # To stage all changes
git add -A                             # This adds, modifies, and removes index entries to match the working tree.
git add -u                             # This removes as well as modifies index entries to match the working tree, but adds no new files.
```

Replace `<file1> <file2> ... <fileN>` with the names of the files you want to stage.

6.3. Explain how to move and rename files using `git mv` and `git rm`.

To move or rename a file, use the `git mv` command:

```bash
git mv old_filename new_filename
```

To remove a file from the repository, use the `git rm` command:

```bash
git rm new_filename
```

## Conclusion
Congratulations! You have completed the Practical Workshop Exercise. By
following these steps, you have set up your Git environment, generated SSH
keys, configured Git, initialized a repository, cloned a remote repository
using both HTTPS and SSH, managed remotes, and performed basic Git operations.

labs/lab2.md

0 → 100644
+19 −0
Original line number Diff line number Diff line
# Lab 2

* git branch, --list, -v, -vv, -a

* git switch

* git switch -c, -C, git restore [--staged], git checkout

* .git/refs .git/HEAD

* git commit -a -m -v

* git branch -m

* git merge, --ff, --no-ff, --ff-only

* git branch -d

* git push [origin [:remote_branch_to_delete]]

labs/lab2.solution.md

0 → 100644
+96 −0
Original line number Diff line number Diff line
# Lab 2

## Solution

### Step 1: Git Branching Concepts

Branching allows developers to work on different features or bug fixes independently without affecting the main codebase. It enables parallel development, making collaboration more efficient and enabling experimentation without compromising the main branch's stability.


To list all local branches:
```bash
git branch --list
```

To list branches along with their last commit messages:
```bash
git branch -v
```

To list branches along with their remote-tracking branches:
```bash
git branch -vv
```

To list all branches, including remote branches:
```bash
git branch -a
```

### Step 2: Creating and Switching Branches

To create a new branch and switch to it:
```bash
git switch -c new_branch_name
```

To create a new branch and switch to it, even if the branch name already exists (will overwrite):
```bash
git switch -C existing_branch_name
```

Starting from Git version 2.23, git switch is recommended for branch switching as it has a more straightforward and safer behavior compared to git checkout.

### Step 3: Working with Files and Commits

To discard changes in a specific file and restore it to the last committed version:
```bash
git restore file_name
```

To stage all modified and deleted files and commit with a message:
```bash
git commit -a -m "Your commit message"
```

The -v option displays the diff of the changes being committed in the commit message editor. It helps you review your changes before finalizing the commit.

### Step 4: Branch Renaming and Merging

To rename the current branch:
```bash
git branch -m new_branch_name
```

To rename a different branch:
```bash
git branch -m old_branch_name new_branch_name
```

Merging combines changes from one branch into another. The following command will merge feature_branch into the current branch:

```bash
git merge feature_branch
```

### Step 5: Deleting Branches

To delete a fully merged branch:
```bash
git branch -d branch_to_delete
```

To delete a remote branch, use the following command:

```bash
git push origin --delete remote_branch
```
Replace remote_branch with the name of the remote branch you want to delete.

## Conclusion
You've now learned essential branching and merging concepts in Git. Branches
allow for parallel development, making collaboration more efficient. You've
also explored how to create, list, switch, rename, and delete branches, as well
as how to work with files and commits effectively. Understanding these concepts
will enable you to manage complex projects and collaborate with other
developers seamlessly.

labs/lab3.md

0 → 100644
+12 −0
Original line number Diff line number Diff line
# Lab 3

* Fork this repo
* Clone your fork and set up origin and upstream remotes properly
* Contribute using a merge request
  * Create a new base branch for the merge request
* Open autumn2023.md and write down what’s the most valuable thing you learnt so far on this course
* Commit and push to your fork
* Open the merge request
* CI needs to pass

Tutor, do that :) Create an MR that fixes TBD's in this document.
Loading