Why habits matter
You know the commands. Now let us build the habits that make a repository trustworthy. This is Git and GitHub from zero, episode seven: good habits on GitHub. A gitignore file, tags, SSH keys, and a README.
Real-life analogies
Here is the everyday version. A gitignore file is a do-not-pack list. Things on it never go into the box. git rm --cached takes something off the shelf, but keeps your copy at home. A tag is a sticker on a box, such as version one point zero. An SSH key pair is a lock and a key. GitHub keeps the lock. You keep the key, and never share it. And a README is the front cover, which tells visitors what the project is.
The .gitignore file
First, the .gitignore file. Some files should never be in Git: passwords, API keys, downloaded packages like node modules, and log files. Create a file called .gitignore, and list one pattern per line. Git now acts as though those files do not exist. They vanish from git status. Add it in your very first commit. A secret that reaches GitHub should be treated as leaked.
git rm --cached
But what if you already committed a file you should have ignored? Adding it to gitignore is not enough. Git keeps tracking files it already knows. git rm --cached, and the file name, stops tracking it, but keeps the file on your disk. Commit the change, and from then on it is ignored. Important: the file is still in your old history. If it was a secret, change the secret.
git tag
Next, git tag. A tag gives a commit a permanent, human-friendly name, like v1.0.0. Use tags to mark releases. It is easy to come back to exactly that version later. git tag -a creates an annotated tag with a message. That is the one to use for releases. Tags are not pushed automatically. Run git push origin, and the tag name.
SSH keys for GitHub
Now, signing in to GitHub without typing a password every time. SSH uses a key pair: a public key, and a private key. Run ssh-keygen with the ed25519 type, and press enter to accept the defaults. A passphrase is a good idea. The public key, ending in dot pub, goes into your GitHub settings. The private key never leaves your computer. Test it with ssh -T git@github.com. GitHub greets you by name. Then use the SSH address of your repository, instead of the HTTPS one.
README and Issues
Finally, make your repository welcoming. A README file is the first thing visitors see. Say what the project does, how to run it, and how to help. GitHub shows it on the front page of your repository. Use Issues to track bugs and ideas, so work does not live only in your head. Many employers look at your GitHub profile. A tidy repository with a clear README shows care.
Recap
Recap. Ignore secrets and clutter. Stop tracking files you should not have committed. Tag your releases. Use an SSH key. And write a README.
Course complete
That completes the course. You can now save, branch, share, and rescue your work. Add Git and GitHub to your Master Profile on ChangeCV, and find more free courses at changecv.com/skills.