You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 15-Appendices.md
+199
Original file line number
Diff line number
Diff line change
@@ -271,12 +271,211 @@ Or, you can write your own!
271
271
272
272
# Submitting homework with Git
273
273
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):
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.
#### 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)
*[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
+
274
472
275
473
[^another]: Windows is also an operating system.
276
474
[^google]: Uh... Google it.
277
475
[^pun]: Pun intended.
278
476
[^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;
279
477
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.
0 commit comments