If you're new to the command line please see the CLI crash course first. Similarly, there's a Git crash course also.
This crash course is aimed at my Data Structures students in CS 2270 at CU-Boulder. Others might find it useful, though this is hardly the only "how to c++" thing on the web. This is tailored for the particular workflow in our course.
The general workflow for 2270 homework assignments is:
- Use
git
to clone a repository. Our repositories have restricted access so you need to either set up your SSH key, or use a personal access token (PAT). - Change directory into that repo's
build
directory. - Run
cmake ..
one time to set up the build process for your computer (because it is different between Windows/Mac/Linux). Using CMake is popular but not universal. - Edit your code in your favorite editor.
- Run
make
to build the app and test binaries. - Run
./run_tests
to see what works and what doesn't. - Go back to step 4 and repeat until you win!
- Hint: you can use the up arrow to scroll through previous commands.
- Hint: Type
make && ./run_tests
to build and run tests in a single command.
- When you're ready to check in your code, use a series of git commands to manage your changes:
git status
to see what changes you've made. It gives a list of files that you could work with.git add
to stage files one at a time or in a big batchgit commit
to store the changes on your local computer, along with a commit messagegit push
to store your changes on the remote computer (which is GitHub in our case).
The above process is exactly the same if you're using an editor with built-in tooling. I personally use VS Code, and I can use either my editor or the CLI to do these things, since ultimately they are working on the same source of truth. The CLI is generally available everywhere though, so you should try to learn how to do it.
Here's an example session with output removed to demonstrate:
$ git clone [email protected]:cu-cspb-2270-Fall-2023/pa8-johnsogg.git
$ cd pa8-johnsogg
pa8-johnsogg git:(master) $ cd build
build git:(master) $ cmake ..
build git:(master) $ make
build git:(master) $ ./run_tests
build git:(master) $ git status
build git:(master) $ git add ../code/Huffman.cpp
build git:(master) $ git commit -m "Made it super perfect"
build git:(master) $ git push