As useful as version control is, we often want to share our code with others, or just store it in a safe place. A forge is a service to do exactly that. Many forges, even those based on Git, offer many more powerful features, like pull requests and issue management. Right now, we're just going to see how they're used. The choice of forge is yours (you might even host your own!), but we'll start with GitHub.
First, we'll need an account. Go to github.com and sign up for an account if you haven't already.
Once you have your account, log in to github.com. Let's create a new repository!
- On your main page, click the
newbutton - Fill out the details as you see fit. For the moment, let's create a public repository (careful what you put on the internet, kids!).
- Now, use your terminal to navigate to a folder of your choice.
- Run
git clone https://github.com/<your-username>/<your-repository>to clone your own repository!
To push changes to your GitHub account, you'll need some sort of authentication to prove your identity. You have two options: one easier, one more standard.
Once you've chosen and set up one, try making a private repository and cloning it. Ask a friend to try as well—if all has gone well, you should be the only one with access!
GitHub has their own software package that you can use to authenticate—it ties into Git and whenever you try to do something restricted, it checks your credentials. This is generally the easier option, but requires another package.
You can install it as follows:
- Windows:
winget install --id GitHub.cli - MacOS (with Homebrew):
brew install gh - Linux: see GitHub's documentation
Once installed, run gh auth login to authenticate.
SSH keys are commonly used to log in to remote computers, but you can also use them with GitHub and other forges.
- First, run
ssh-keygen(be careful not to overwrite your existing keys if you have any!!). The default options should be fine on most devices. - Now, navigate to
~/.ssh. The previous command should have produced two files, one with a.pubsuffix, for public. Open this file. - On github.com, open your account settings (click on your profile picture).
- Navigate to Access→SSH and GPG keys
- Click
New SSH key - Give your key a title (probably the name or type of your device). Make sure it is set to be an Authentication Key.
- Now copy the content from your
.pubfile into the Key box - Click
Add SSH Key
When you want to use a GitHub repository with ssh authentication, your commands will look a little different. Instead of using https://github.com, you will write ssh://git@github.com. The ssh part tells Git you want to communicate using the SSH protocol, and the git@ part tells GitHub you are trying to access a git repository.
Now that you've authenticated with GitHub, run git clone to clone your repository, as we've done before.
Let's make some changes:
- Add a new file or edit an existing one. Make sure your changes are saved.
- Use
git status,git add, andgit commit -m "<your-message>"to commit your changes to your local repository. - Now run
git pull. You should see that your upstream repository—the one on GitHub—is behind your local one! - Run
git push. If you have correctly authenticated and there are no conflicts, your changes should now be uploaded. Check them on github.com!