Throughout CSE 333, you will use Gitlab and git control flow in order to work collaboratively on homeworks and exercises. This guide will help you get started with Gitlab and how to use Git effectively in this course.
The following instructions are for connecting your CSE Linux environment (attu or VM) to your GitLab repo in preparation for hw0 – hw4. The following section has more tips and tricks for using git as you work on your hw, including if you have a partner.
This will allow you to access your repo without having to authenticate (i.e., type your password) every time and will greatly improve your workflow.
cat ~/.ssh/id_rsa.pub
ssh-keygen -t rsa -C "<netid>@cs.washington.edu"
cat ~/.ssh/id_rsa.pub
Any commands shown below should be run from your CSE Linux environment (attu or VM).
git clone <repo url>
touch README.md
README.md
.git status
README.md
.git add README.md
git status: README.md staged for
commit
git commit -m "First Commit"
git status: Your branch is
ahead by 1 commit
git push
Once you have a made a local copy of your Gitlab repository in your CSE Linux environment (attu or VM), you can now have access to and make changes to files your repository locally! However, note that the repository on Gitlab and the copy in your CSE environment do not automatically update with each other, so we have an additional responsibility of keeping both of them up to date (so you don't have unupdated copies).
It is recommended to look through the expected git workflow on this page (if you are interested in more details, the Git Community Book is a great resource as well).
Update your local copy of the repository with information in the Gitlab repository, type into the command line (in your local repository):
[attu]$ git pull
Commit and add changes from your local copy to the Gitlab repository:
[attu]$ git pull # make sure your local copy is up to date with Gitlab
[attu]$ git add <files> # stages files to commit to Gitlab
.
(period character) in
<files>
from the top-level git
repository directory to stage all files to be added to
Gitlab repository. (Note: .
represents current
directory, so at top-level of the repository, you are
adding and staging all changes in local copy of the
repository!)git add
that you do
not want to commit to the Gitlab repository[attu]$ git commit -m “<message here>” # add a descriptive message about your update
[attu]$ git push # push your changes to your Gitlab
.gitignore
file that will state which files will be ignored when updating
the Gitlab repository. This may be particularly useful for not
including executables or object files (.o
files),
which is already done for you. You can add more files that you
may not want to include in .gitignore
.
Keeping your workspace organized is crucial to keeping your flow smooth, efficient, and as productive as it can be. By making sure to frequently update your local and Gitlab repository, you reduce the chance in getting. Nevertheless, you will end up in a “Git spaghetti ball,” so here are some useful survival tips and commands.
These git commands are ways to manage local changes to your git repository before pushing to your Gitlab repository.
git stash
git stash pop
git stash drop
git reset --hard HEAD
git checkout HEAD -- path/to/file
git reset --soft HEAD~1
Sometimes, you may have added a commit that you don't like and wish to remove, but you have already pushed it onto Gitlab! No worries, there is a way to handle this. (these instructions take inspiration from Gitlab documentation)