Search
Git cheatsheet (Github), Git cheatsheet (GitLab), Git cheatsheet (Aalto uni), …
git init - start a repository in this folder
git init
git clone <location> - copy the remote repository into the current folder
git clone <location>
git add <filename> - flag the file to be commited
git add <filename>
git commit -m “<message>” - create the commit
git commit -m “<message>”
git diff <filename> - see how the file has changed since it was last commited
git diff <filename>
git status - see which files have changed since the last commit
git status
git log - see the history
git log
git checkout <hash> - set the repository to the state at this commit
git checkout <hash>
git remote add <aliasName> <aliasLocation> - set up a new remote location
git remote add <aliasName> <aliasLocation>
git remote remove <aliasName> - remove remote
git remote remove <aliasName>
git remote show - see all remotes, you can add <aliasName> to get detailed information about specific remote
git remote show
git pull <aliasName> <branch> - bring remote commits into the current repository
git pull <aliasName> <branch>
git push <aliasName> <branch> - put any local-only commits onto the remote machine
git push <aliasName> <branch>
git branch - list branches
git branch
git branch <newbranchname> - create a new branch
git branch <newbranchname>
git checkout <branchname> - switch to branch
git checkout <branchname>
git checkout -b <newbranchname> - create a new branch from the current repository situation and switch to it
git checkout -b <newbranchname>
git merge <branchname> - merge the specified branch to the current one
git merge <branchname>
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).
git stash
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.
git pull
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.
How Git Works: Explained in 4 Minutes
Git MERGE vs REBASE: Everything You Need to Know
Merging vs rebasing (advanced)