Throughout CSE 333, you will use Gitlab and git control flow in order to work collaboratively on exercises and homework. 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 CSE Linux VM) to your Gitlab repo in preparation for all of the Homework. The later Git Workflow section has tips and tricks for using git as you work on the Homework, including if you are collaborating with a partner.
This will allow you to access your repo without having to authenticate every time (i.e., no more typing your password!) 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
The git commmand looks for a file called .gitconfig located in your home directory that contains a variety of options that control git's behavior. Some commands (e.g., commit and push) will produce verbose warning messages if certain options are unset; these commands will properly configure git. If you've set up git before, this section can be safely skipped as these commands only need to be run once per user (though running them again won't cause any harm).
$ git config --global user.name "<your name>"
$ git config --global user.email "<your netid>@cs.washington.edu"
$ git config --global push.default simple
$ git clone <repo url>
$ cd cse333-23sp-<netid>
$ 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 the CSE Linux environment (attu or CSE Linux VM), you can now make changes to files your repository locally!
The expected git workflow on this page should suffice for CSE 333, but you can find more details in the .
Navigate to anywhere within your local repository and use the command:
$ git pull
.gitignore
file is included in your initial repo
that will omit object files (.o
files) and text editor
backup files automatically.
You may add more files to be ignored to .gitignore
, if
desired.
Make sure that you are in your local repository and that all updates to files have been saved before using the following commands:
$ git pull # make sure your local copy is up to date with Gitlab
$ git add <files> # stages files to commit to Gitlab
.
(period character)
as <files>, which will stage all
added/deleted/modified files in the local repo because
.
represents the current directory.
$ git commit -m "<message>" # add a descriptive message about your update
$ git push # push your changes to Gitlab
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 repositories, you reduce the chance of getting into weird situations. Nevertheless, it is common to end up in a "Git spaghetti ball" every so often, so here are some useful survival tips and commands.
The following git commands are ways to manage local changes to your repository before pushing to Gitlab:
$ git reset --hard HEAD
$ git checkout HEAD -- <path to file>
$ git reset --soft HEAD~1
$ git stash
This is a way to remove a commit that you pushed to Gitlab but no longer like. These instructions take inspiration from .