Throughout CSE 333, you will use Gitlab and git control flow to work on the project homework assignments. This guide will help you get started with Gitlab and discuss how to use Git effectively.
These instructions are for connecting your CSE Linux environment (attu, lab workstation, 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.
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. You should do this since password authentication can be awkward at best for routine gitlab use.
cat ~/.ssh/id_rsa.pub
ssh-keygen -t rsa -C "<netid>@cs.washington.edu"
cat ~/.ssh/id_rsa.pub
Git uses a .gitconfig
file in your home directory to store
options that you have configured. We suggest that you don't include much
here since the defaults are generally what you want and changing defaults can
lead to confusing or unexpected behavior.
However there are three options that you should set so that git will not pester
you with warnings every time you try to commit or push changes. You should
enter the following commands once before you start using
git/gitlab:
git config --global user.name "Your Name" git config --global user.email username@cs.washington.edu git config --global push.default simpleSubstitute your own name and email address, of course. If you use git on more than one machine, you will need to do this once on each machine.
Any commands shown below should be run from your CSE Linux environment (attu, lab workstation, 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, lab workstation, 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 synchronize with each other, so you have an additional responsibility of keeping both of them up to date (so you don't have out-of-date copies in either place or lose work if something goes wrong with your local copy of the repo).
We recommend you use the git workflow described here. (If you are interested in more details, the Git Community Book is a great resource as well).
To update your local copy of the repository with any new information in the Gitlab copy of the repository, type the following command (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 list files and file types that 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
.
However, for CSE 333 we strongly recommend that you do not make
changes to the distributed .gitignore
file, since some changes
that might seem useful have been known in the past to interfere with distribution
of binary files that need to be included with homework project starter code.
Keeping your workspace organized is crucial to keeping your workflow smooth, efficient, and as productive as it can be. By making sure to frequently update your local and Gitlab repository, you reduce the chances of getting into trouble. Nevertheless, you might end up with a “Git spaghetti ball,” so here are some useful survival tips and commands.
Avoid branching, merging, and other complex git structures in your CSE 333 gitlab repo. While these are widely used in large projects and in industry, they are not needed for CSE 333 (our project structure is not that complex). When not used correctly, these can leave your repo in an unexpected state where new changes seem to disappear or other odd things happen. Keep it simple.
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