====== Lab 11 - Version Control ====== ==== Cheatsheet - Reminder of essential commands ==== {{https://training.github.com | Git cheatsheet (Github)}}, {{https://about.gitlab.com/images/press/git-cheat-sheet.pdf | Git cheatsheet (GitLab)}}, {{https://aaltoscicomp.github.io/cheatsheets/git-cheatsheet.pdf | Git cheatsheet (Aalto uni)}}, ... == Creation == ''git init'' - start a repository in this folder ''git clone '' - copy the remote repository into the current folder == Basic file operations == ''git add '' - flag the file to be commited ''git commit -m ""'' - create the commit ''git diff '' - 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 '' - set the repository to the state at this commit == Push/Pull == ''git remote add '' - set up a new remote location ''git remote remove '' - remove remote ''git remote show'' - see all remotes, you can add to get detailed information about specific remote ''git pull '' - bring remote commits into the current repository ''git push '' - put any local-only commits onto the remote machine == Branches == ''git branch'' - list branches ''git branch '' - create a new branch ''git checkout '' - switch to branch ''git checkout -b '' - create a new branch from the current repository situation and switch to it ''git merge '' - 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 local repository. 2. Add your files to the local repository and commit them. 3. Log in to your {{https://gitlab.fel.cvut.cz | FEL GitLab}} account. For access you will need to create {{https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html#project-access-tokens | project access token}} or generate {{https://docs.gitlab.com/ee/user/ssh.html | ssh-key}}. 4. Create a new empty repository on GitLab. 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 '', 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. {{ :courses:be5b99cpl:labs:winter-is-coming-brace-yourself-merge-conflicts-are-coming.jpg?nolink&250 |}} **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. ====Useful links==== {{https://youtu.be/e9lnsKot_SQ?si=qGs-mHrhkq71woXw | How Git Works: Explained in 4 Minutes}} {{https://youtu.be/0chZFIZLR_0?si=Kbv0PlTElGw9XND_ | Git MERGE vs REBASE: Everything You Need to Know}} {{https://www.atlassian.com/git/tutorials/merging-vs-rebasing | Merging vs rebasing (advanced)}}