GitHub Tips and Tricks
GitHub is where you will keep the code for almost every class you take, and it is also where future employers will go to look at your work. This page covers the setup you need once, the habits that will save you at 11:45pm the night a project is due, and some cool features that most students never find.
GitHub Education
Verified students get a bunch of paid GitHub features for free, including GitHub Copilot and the same Codespaces quota as a GitHub Pro account. You will need to sign up with your Boise State email address so GitHub can verify that you are a student.
You never have to pay for GitHub. All assignments can be completed with the free tier, and if you run out of free Codespaces hours you can use the CS department lab machines to finish your projects.
DANGER
Some professors in the CS department view using A.I. tools such as Copilot as cheating, and the rules are different in every class. Read the syllabus in each of your classes and look for the policy on A.I. tools before you use them.
Use one account for everything
Use one personal GitHub account for all of your classes. Do not create a new account each semester or a throwaway account for a single class. Your account will follow you after you graduate, so in a few years it becomes a portfolio of everything you have built.
Add your Boise State email to your account under Settings > Emails, even if your personal email is your primary one. Then make sure git on every machine you use knows who you are.
git config --global user.name "Your Name"
git config --global user.email "you@u.boisestate.edu"The email in git config must match one of the emails on your GitHub account. If it does not, your commits will not be linked to your account, and your instructor cannot easily tell that they are yours.
Keep your coursework private
Unless your instructor tells you otherwise, every repository with your homework or projects in it should be private. A public repository with your solution in it lets anyone copy your work, and if another student turns in your code you can both end up in an academic integrity meeting. This applies after the class is over too, since most instructors reuse their projects.
The one exception is a forked repository. GitHub does not let you make a fork of a public repository private, so do not use the Fork button to start an assignment. Use the template approach below instead.
Starting from starter code
Most starter code is published as a template repository. A template gives you a brand new repository of your own with a copy of the code, and you get to pick whether it is public or private.
- Open the starter code repository your instructor gave you.
- Click Use this template and then Create a new repository.
- Pick a name, select Private, and click Create repository.
You can do the same thing from the command line with the gh tool (setup is at the bottom of this page).
gh repo create my-project --private --clone --template OWNER/STARTER-REPOSharing a repository with your instructor
Since your repository is private, your instructor cannot see it until you give them access. If your class asks you to submit a link to your repository, go to Settings > Collaborators, click Add people, and add your instructor's GitHub username. Do this before the due date. A link your instructor cannot open is the same as not submitting anything.
Commit early and often
Commit every time you get something working, and push at the end of every session. Your commit history is a backup, an undo button, and a record that shows how you built your project over time. A project that shows up in one giant commit the night it is due is a lot harder to defend if anyone ever has questions about where the code came from.
Write commit messages that say what you did: "Add input validation to parse_args", not "stuff" or "asdf". Future you will thank you.
Do not commit secrets or junk
Some things should never end up in your repository:
- Passwords, API keys, and tokens
- Build output (
*.o, executables,build/,dist/) - Dependencies you can download again (
node_modules/,venv/) - Editor and OS files (
.DS_Store,.idea/)
List these in a .gitignore file in the root of your repository so git ignores them. GitHub keeps a collection of .gitignore templates for most languages, so you can start from one of those.
WARNING
If you push a password or API key by mistake, deleting the file in a new commit is not enough. It is still in your history. Revoke the key and generate a new one right away.
Check the green check mark
Some classes use GitHub Actions to build and test your code every time you push. Look for the icon next to your latest commit on github.com. A green check means everything passed, a red X means something failed, and you can click it to see the output. Check this before you submit, not after.
Working on a team project
When you work with other students in the same repository, do not all push to main. Each person should work on their own branch and merge it with a pull request.
git switch -c add-login-page
# do some work and commit it
git push -u origin add-login-page
gh pr create --fillA pull request gives your teammates a chance to review your code before it is merged, and GitHub keeps a record of who did what. This is how almost every software team works in industry, so it is a good habit to build now.
Quick edits in the browser
Press the . key while you are looking at any repository on github.com and it opens in a lightweight version of VS Code right in your browser. It is great for fixing a typo or editing a README, and it does not use any of your Codespaces hours. It does not have a terminal though, so you cannot build or run anything.
Fixing common mistakes
I forgot to add a file to my last commit
As long as you have not pushed yet, add the file and amend the commit.
git add missing-file.c
git commit --amend --no-editI want to throw away my changes to a file
This puts the file back the way it was at your last commit. Your changes are gone for good, so make sure that is what you want.
git restore src/lab.cMy push was rejected
This usually means there are commits on GitHub that you do not have yet (you pushed from another machine, or a teammate pushed). Pull them in first and then push again.
git pull --rebase
git pushI pushed a commit that broke everything
Create a new commit that undoes it. Use git log --oneline to find the commit id.
git revert a1b2c3d
git pushMy repository is a mess and I do not know how to fix it
Do not delete anything yet. Clone a fresh copy of your repository into a new folder, copy the files you changed over to it, and commit them there. If you are still stuck, come to office hours and bring the URL of your repository.
Configure GitHub
This section walks you through configuring your personal GitHub account so you can work effectively from the command line in your future classes.
Install the command line client
You can skip this task if you are working on one of the CS lab machines. The gh command line tool is already installed for you.
Install the GitHub command line client cli.github.com.
Windows users MUST reboot their machines. If you are on Windows, do not continue until you have rebooted your machine. Once the gh tool is installed you should be able to open a terminal and type gh as shown below.
$ gh
Work seamlessly with GitHub from the command line.
USAGE
gh <command> <subcommand> [flags]
... Lots more output!Set Up Authorization
We want to configure our machine to use ssh keys using the command gh auth login. Other tools and some integrated development environments (IDEs) need ssh to work properly. This will ensure that your setup will work no matter how you choose to write code 😃.
$ gh auth login
? Where do you use GitHub? GitHub.com
? What is your preferred protocol for Git operations on this host? SSH
? Generate a new SSH key to add to your GitHub account? Yes
? Enter a passphrase for your new SSH key (Optional):
? Title for your SSH key: GitHub CLI
? How would you like to authenticate GitHub CLI? Login with a web browser
! First copy your one-time code: XXXX-XXXX
Press Enter to open https://github.com/login/device in your browser...
✓ Authentication complete.
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
✓ Uploaded the SSH key to your GitHub account: /home/shane/.ssh/id_ed25519.pub
✓ Logged in as shanepConfirm everything works
We want to confirm that we have everything set up correctly. Luckily, the command line tool has an option to do this for us. Run the command gh auth status and you should see output similar to what is shown below.
Your output will be slightly different depending on the OS and other factors. You are not required to match the output exactly. You just need to confirm that github.com is configured to use the ssh protocol.
$ gh auth status
github.com
✓ Logged in to github.com account shanep (keyring)
- Active account: true
- Git operations protocol: ssh
- Token: gho_************************************
- Token scopes: 'admin:public_key', 'gist', 'read:org', 'repo'Congrats, you are now configured to use github.com with the ssh protocol!