Lab 11 - Version Control

Cheatsheet - Reminder of essential commands

Creation

git init - start a repository in this folder

git clone <location> - copy the remote repository into the current folder

Basic file operations

git add <filename> - flag the file to be commited

git commit -m “<message>” - create the commit

git diff <filename> - see how the file has changed since it was last commited

git status - see which files have changed since the last commit

Moving around

git log - see the history

git checkout <hash> - set the repository to the state at this commit

Push/Pull

git remote add <aliasName> <aliasLocation> - set up a new remote location

git remote remove <aliasName> - remove remote

git remote show - see all remotes, you can add <aliasName> to get detailed information about specific remote

git pull <aliasName> <branch> - bring remote commits into the current repository

git push <aliasName> <branch> - put any local-only commits onto the remote machine

Branches

git branch - list branches

git branch <newbranchname> - create a new branch

git checkout <branchname> - switch to branch

git checkout -b <newbranchname> - create a new branch from the current repository situation and switch to it

git merge <branchname> - merge the specified branch to the current one

Exercises

Exercise 1 - Pushing to GitLab:

1. Use the folder/code from the previous lab. Run git init to make it into a repository.

2. Add your files to the repository and commit them.

3. Log in to your FEL GitLab account. For access you will need to create project access token or generate ssh-key.

4. Create a new repository. Push your work there (you need to set remote).

5. Create a basic readme file called “Readme.txt” - make sure it is spelled exactly like this (including capitals). Add this as a second commit and push it to the GitLab repository also.

6. After committing, make another change to the “Readme.txt” file, but do not commit it to the GitLab repository.

Exercise 2 - Push to someone else's repository:

1. Find a partner. Clone their GitLab repository from the exercise 1.

2. Add your name to a new line in their “Readme.txt” file. Push it back to their repository (you may need them to grant you access in the GitLab web interface).

Exercise 3 - Merge everything:

1. Once someone has modified your online repository, try to pull the changes. Read the messages and figure out how to do this (you may stage your changes before pulling with git add <filename>, or you can save your current changes with git stash, pull and then use git stash pop).

2. Once you have your changes and theirs merged, push it back to the repository. Get your partner to run git pull - they should have everything on their machine.

Exercise 4 (optional) - Branch, Merge everything:

1. Again, work on the same repository with your partner. Each creates a new branch (e.g. dev-A and dev-B).

2. Add new features (text, numbers, lines, …) to the “Readme.txt” file in your branch.

3. Both commit your changes and push them to the remote repository.

4. First, merge branch dev-A with main branch (fast-forward merge, no commit was done to the main branch in the meantime)

5. Second, the person who created dev-B run git pull and merge dev-B to main branch.

courses/be5b99cpl/labs/lab11.txt · Last modified: 2024/12/04 10:59 by janotjir