Skip to content

Commit 677f525

Browse files
committed
Add an appendix on submitting with git
1 parent 94f62fe commit 677f525

File tree

1 file changed

+199
-0
lines changed

1 file changed

+199
-0
lines changed

15-Appendices.md

+199
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,211 @@ Or, you can write your own!
271271

272272
# Submitting homework with Git
273273

274+
Your instructor may have you submit your assignments using Git and GitLab.
275+
These tools (or tools like them) are commonly used in industry, so getting accustomed to them early will pay off in the long run.
276+
277+
Git is an open source, distributed version control system that allows programmers to track changes made to source files and share those changes with collaborators.
278+
It was created by Linus Torvalds (the Linux guy) and has become hugely popular in the last several years.
279+
280+
GitLab is an open source web application that makes it a bit easier for programmers to collaborate on programming projects.
281+
GitLab lets users create repositories (projects) on a central server.
282+
Users can then push their code to GitLab using git.
283+
From there, users can clone their code to other machines, push up new changes, etc.
284+
You could think of it (kind of) like Dropbox – GitLab is a central place to store your code.
285+
286+
In addition to storing code, GitLab has many features to help users collaborate with others.
287+
Users can share projects with other users, giving them the ability to push/pull code to/from the project.
288+
There are also bug tracking utilities, code review tools, and much more.
289+
290+
In this class, we'll be using just the git parts of GitLab, so don't worry if the fancier features sound difficult.
291+
All you need to be able to do is
292+
293+
- View the GitLab website.
294+
- Retrieve (clone) the lab assignments.
295+
- Record (commit) your solutions to those assignments.
296+
- Upload (push) those solutions back to GitLab.
297+
298+
Once you are done with an assignment, you should **always** check GitLab to make sure that your solutions are properly uploaded.
299+
300+
## Warning
301+
302+
Do not blindly copy and paste git commands from the internet and run them.
303+
(This isn't specific to git --- that's just plain ol' good life advice right there.)
304+
While all the common git commands are quite good at not losing your hard work, there *are* commands that can wreak havoc if used improperly.
305+
If you don't know what a command does, take a few minutes to read some documentation on it first.
306+
307+
If things are not working right, first check `git status` and `git log` to see what git thinks has happened.
308+
When that doesn't clear things up, have a look on your favorite search engine and/or ask a friend or your instructor for help.
309+
*Definitely* ask someone if the internet is recommending you run unfamiliar git commands!
310+
311+
## Configuring Git
312+
313+
Before you can use git, you need to configure a couple of things.
314+
315+
### Who Are You?
316+
317+
Don't worry, no need for an existential crisis.
318+
Git just wants to know your name and your email address.
319+
320+
Open a terminal (i.e., PuTTY) and run these commands (substituting your own name and email, of course):
321+
322+
```
323+
$ git config --global user.name "Hank Chicken"
324+
$ git config --global user.email [email protected]
325+
```
326+
327+
Git probably won't say anything when you run these commands; it's the strong silent type.
328+
Don't worry, you're fine.
329+
330+
### Editing
331+
332+
Git sometimes will open a text editor so you can type in certain things (mainly commit messages).
333+
The default editor it uses is joe, which almost no one knows how to use.[^exit-joe]
334+
You will most likely want to set the editor to one you know and love.
335+
336+
To change the editor to `jpico`, run the following command (substitute a different editor if you like):
337+
338+
```
339+
$ git config --global core.editor jpico
340+
```
341+
342+
<!--
343+
### Authentication (optional)
344+
345+
GitLab supports two forms of authentication: HTTPS and SSH.
346+
HTTPS authentication "just works" - - - there's no setup needed.
347+
It does, however, require you to enter your username and password each time you pull or push.
348+
349+
SSH authentication requires some setup and still won't work out of the box on the CLC machines.
350+
So just give up and use HTTPS, because computers are terrible.
351+
352+
If you do want to use it, though, read [this guide](https://git-classes.mst.edu/help/ssh/README).
353+
-->
354+
355+
## Working on assignments
356+
357+
Here's the gist of how to do assignments:
358+
359+
1. Get the assignment
360+
- Clone the repository
361+
- Open the assignment directions
362+
2. Do the assignment
363+
- Commit changes as you go
364+
- Push to GitLab if you like
365+
3. Turn it in
366+
- Push all your work to GitLab
367+
- Check the GitLab website to make sure your submission looks right
368+
369+
### Getting the assignment (`git clone`)
370+
371+
For each lab assignment you will be granted access to a git repository on GitLab that contains starter code and examples.
372+
These repositories are visible only to you and the instructor and graders.
373+
You will be granted [developer](http://docs.gitlab.com/ce/user/permissions.html) permissions to your repositories.
374+
This will allow you to view the project and push changes to it.
375+
376+
When you start an assignment, the first thing you must do is download a copy of the repository so you can make changes to it.
377+
378+
1. Log in to [https://git-classes.mst.edu](https://git-classes.mst.edu).
379+
2. Navigate to the project that you want retrieve.
380+
3. Copy your repository’s URL from the text box in the middle of the page beneath the assignment name.
381+
- If you don't see it, try making your browser window wider. Hooray responsive web design!
382+
- Cloning over HTTPS (easy):
383+
1. Select 'HTTPS' from the dropdown next to the text box.
384+
2. Copy the URL from the text box. It should start with `https://git-classes.mst.edu`.
385+
- Cloning over SSH (if you have [ssh keys](https://git-classes.mst.edu/help/ssh/README) configured):
386+
1. Select 'SSH' from the dropdown next to the text box.
387+
2. Copy the URL from the text box. It should start with `[email protected]`.
388+
4. Open up a terminal (i.e., PuTTY) and navigate to the directory (using `cd`) where you want to put your copy of the repository.
389+
5. Run `git clone <URL you copied in step 3>`.
390+
391+
That’s it! Now you’ve cloned your repository down, and you’re ready to get started.
392+
393+
**Resources:**
394+
395+
* [Pro Git: Cloning an Existing Repository](https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository#Cloning-an-Existing-Repository)
396+
* [Atlassian Git Tutorials: git clone](https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-clone)
397+
398+
### Working on the assignment
399+
400+
As far as working on the files go, there’s nothing special you have to do. Edit them, compile them, have fun with them. When you’re ready to commit (take a snapshot of) your code, you’ll need to interact with git.
401+
402+
#### Committing code (`git commit`)
403+
404+
1. Run `git status` to see which files are **staged**, **modified**, or **untracked**.
405+
- **staged** files will be included in the next commit.
406+
- **modified** files have been modified, but they haven’t been staged for commit.
407+
- **untracked** files are unfamiliar to git. They exist in the folder, but git isn’t paying any attention to changes made to them.
408+
2. Stage all changes that you want to commit.
409+
- Stage files by using the `git add` command.
410+
- For example: `git add main.cpp`.
411+
3. Run `git status` again to make sure that the correct files are staged for commit.
412+
4. Run `git commit`. This will create a snapshot – recording the staged changes.
413+
5. Enter a meaningful commit message in the text editor that opens. Then save and close it.
414+
415+
Now your changes have been committed!
416+
417+
**Resources:**
418+
419+
* [Pro Git: Recording Changes](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#Checking-the-Status-of-Your-Files)
420+
* [Atlassian Git Tutorials: Saving changes](https://www.atlassian.com/git/tutorials/saving-changes)
421+
422+
423+
#### Looking through your Repository (`git status`, `git log`)
424+
425+
There are a couple of commands that come in handy for viewing the state of your repository:
426+
427+
- `git status`: View the current state of files. What has changed? What’s new in the repository?
428+
- `git log`: Shows a timeline of commits. See a history of changes made to a repository.
429+
430+
**Resources:**
431+
432+
* [Atlassian Git Tutorials: Inspecting a repository](https://www.atlassian.com/git/tutorials/inspecting-a-repository)
433+
434+
435+
#### Pushing your Commits (`git push`)
436+
437+
After you’ve committed something, you can push it to GitLab with git push.
438+
We recommend pushing frequently, just for peace of mind.
439+
440+
1. Run `git push`
441+
- If you cloned over HTTPS, Git will ask for your username and password. Those are the same as the ones you use to log into GitLab.
442+
2. Check GitLab to ensure your code looks as expected.
443+
- This step isn’t strictly required. However, if you’re not used to working with Git, it is in your best interest to ensure your code looks right. We’re going to grade what’s in GitLab, after all.
444+
445+
**Resources:**
446+
447+
* [Pro Git: Pushing to your Remotes](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes#Pushing-to-Your-Remotes)
448+
* [Atlassian Git Tutorials: git push](https://www.atlassian.com/git/tutorials/syncing/git-push)
449+
450+
451+
### Turning in your assignment (`git push`)
452+
453+
Once you've completed your assignment, make sure to commit and push all your work!
454+
If your work isn't on GitLab, we can't grade it.
455+
You should also check GitLab to make sure your submission isn't missing any files.
456+
457+
## Helpful Resources
458+
459+
These are some nice resources for learning more about Git:
460+
461+
* [In-browser Git Tutorial](https://try.github.io/levels/1/challenges/1)
462+
(**Do this one.** It's a nice tutorial.)
463+
* [Atlassian's Git Tutorials](https://www.atlassian.com/git/tutorials)
464+
* [Pro Git](https://www.git-scm.com/book/en/v2)
465+
* [GitLab's Help Pages](https://git-classes.mst.edu/help/gitlab-basics/README.md)
466+
(You may need to log into git-classes.mst.edu for that to work.)
467+
* [Introductory Videos from GitHub](https://git-scm.com/videos)
468+
469+
If you see mentions of BitBucket or GitHub around, they're just web applications like GitLab.
470+
Same basic idea, created different people.
471+
274472

275473
[^another]: Windows is also an operating system.
276474
[^google]: Uh... Google it.
277475
[^pun]: Pun intended.
278476
[^2d]: Yep, it's a two-dimensional array. We use `char**` rather than something like `char[][100]` since we don't know how big the array or its subarrays will be;
279477
the operating system works this out when it runs your program.
478+
[^exit-joe]: By the way, \keys{\ctrl + k + x} will exit joe, should you forget to configure your editor before using git.
280479

281480
<!-- LocalWords: PuTTY
282481
-->

0 commit comments

Comments
 (0)