Step 1: Install Git
On Windows, download from https://git-for-windows.github.io/
On Mac, download from https://git-scm.com/download/mac
On Linux, download git
from your package manager
Step 2: Make an account on https://github.com/
Step 3: Using the GitHub website, make a new repository (Austin will show how) and call it something like testrepoLOL
Step 4: Open the Terminal program (Windows users should run the new “Git Bash” program)
Step 5: Navigate to wherever you want to download your code using the “cd
” command (short for “change directory”) (Austin will show how)
Warning, you’re about to feel like this: https://www.youtube.com/watch?v=vYNnPx8fZBs
Step 6: “Clone” the repo you just made on the GitHub website. Note that you may have to enter your GitHub login. Use the command below (Austin will show how)
git clone https://github.com/your-user-name/testrepoLOL
Step 7: cd
into the folder you just created
Step 8: Pretend you’re coding and make a new file with some text inside it, like main_program.m
. Note that you don’t need to use the Terminal for this; you can open the folder in your file browser and just make a new file) (Austin will show how)
Step 9: Tell git that you want it to start tracking this new file, including all future changes by “add”-ing it via this command: (Austin will show how)
git add main_program.m
Step 10: Now that we have made some progress on our “code”, we want git to make a “commit” and take a snapshot of the current state of all the currently tracked files. This will bring you into a prompt where you will enter a short message describing this commit, along with any optional metadata you want to mention. Use the command below (Austin will show how)
git commit
Step 11: Everything we’ve done so far has only been on our LOCAL computer, and the GitHub servers are completely unaware. Just like in the presentation, we need to “push” our new commit to GitHub. “origin” is just the default name for the GitHub servers. Use the command below (Austin will show how)
git push origin
Step 12: After a couple of seconds, if you go to your repo at https://github.com/your-user-name/testrepoLOL and look for the main_program.m
file you just added, you should see it on there on the website!
You just used git to version control your work, and you shared it publicly with the rest of the world! Like how science is supposed to be done! You now know 99% of what you need to contribute to the BU-CNSO website, or any other GitHub open source projects!
Helpful guides:
https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow
Step 1: Using the GitHub website, let’s “fork” the “upstream” repo for the new website, which is located at https://github.com/bu-cnso/bu-cnso.github.io (Austin will show how, and explain what “upstream” is)
Step 2: Then, clone your fork, which should be at https://github.com/your-user-name/bu-cnso.github.io. Note that you are NOT cloning the “upstream” repo, but instead YOUR clone!
Step 3: It’s better to do development on branches that are not the master
branch, since the master
branch is often the LIVE/publicly accessible version of the code. So, we want to do our dev on a “feature branch”, so let’s make a new branch AND switch to that branch:
git checkout -b feature_0192
Note: WRITE THIS COMMAND DOWN! I’ll explain why.
Step 4: Make your changes.
Step 5: Commit your changes using
git commit
Step 6: Because you’re on a new branch that has new commits, you need to push BOTH your new branch and your code to the origin/your fork as it exists on the GitHub servers. Use this command (and write it down too!), noting the “-u” flag:
git push -u origin feature_0193
Now, you’re ready to make the Pull Request, or the request for the owners of the “upstream” repo to “pull” the new code on your fork! Go to the GitHub website and make a Pull Request (Austin will show how, and discuss Pull Requests)
Step 7: We’ve finished going over how we contribute TO the upstream repo, but we also need to be able to get future updates FROM new commits of the upstream repo. To see your current remotes, run the command
git remote -v
To add the original, main, “upstream” repo as something to download from directly (i.e. what you forked from, not the fork itself), add it to your list of removes via this command (Note this is from the “bu-cnso” user):
git remote add upstream https://github.com/bu-cnso/bu-cnso.github.io
To keep our fork up to date, we need to first download/“fetch” the changes from upstream
, then apply/“merge” the new commits branch-by-branch, then push these new commits to our origin
. I know this is a lot to unpack, but assuming you’re in the master
branch, use these three separate commands:
git fetch upstream
git merge upstream/master
git push origin