Jose Robledo
04 March 2025
Many options
Let’s start by sharing the changes we’ve made to our current project with the world. To this end we are going to create a remote repository that will be linked to our local repository.
Log in to GitHub, then click on the
icon in the top right corner to create a new repository called
recipes
:
Name your repository “recipes” and then click “Create Repository”.
Note: Since this repository will be connected to a local repository, it needs to be empty. Leave “Initialize this repository with a README” unchecked, and keep “None” as options for both “Add .gitignore” and “Add a license.” See the “GitHub License and README files” exercise below for a full explanation of why the repository needs to be empty.
As soon as the repository is created, GitHub displays a page with a URL and some information on how to configure your local repository
Now we connect the two repositories. We do this by making the GitHub repository a remote for the local repository. The home page of the repository on GitHub includes the URL string we need to identify it:
Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
We use SSH here because, while it requires some additional configuration, it is a security protocol widely used by many applications. The steps below describe SSH at a minimum level for GitHub.
Before we can connect to a remote repository, we need to set up a way for our computer to authenticate with GitHub so it knows it’s us trying to connect to our remote repository.
SSH uses what is called a key pair. This is two keys that work together to validate access. One key is publicly known and called the public key, and the other key called the private key is kept private. Very descriptive names.
This setup only needs to be done once, so if you already did it, you can relax :)
Keys are stored in a folder in your home
directory called .ssh
. You can see it by typing
comment: -t
option specifies which type of algorithm to
use and -C
attaches a comment to the key
You should see something like this:
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/Alfredo/.ssh/id_ed25519):
Since we will use the defautl file, just press Enter.
You will be prompted for a passphrase (optional, you can just press enter to not include a prassphrase).
Your identification has been saved in /c/Users/Alfredo/.ssh/id_ed25519
Your public key has been saved in /c/Users/Alfredo/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:SMSPIStNyA00KPxuYu94KpZgRAYjgt9g4BA4kFy3g1o a.linguini@ratatouille.fr
The key's randomart image is:
+--[ED25519 256]--+
|^B== o. |
|%*=.*.+ |
|+=.E =.+ |
| .=.+.o.. |
|.... . S |
|.+ o |
|+ = |
|.o.o |
|oo+. |
+----[SHA256]-----+
First, we need to copy the public key. Be sure to include the
.pub
at the end, otherwise you’re looking at the private
key.
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDmRA3d51X0uu9wXek559gfn6UFNF69yZjChyBIU2qKI a.linguini@ratatouille.fr
Now, going to GitHub.com, click on your profile icon in the top right corner to get the drop-down menu. Click “Settings”, then on the settings page, click “SSH and GPG keys”, on the left side “Access” menu. Click the “New SSH key” button on the right side.
Paste your SSH key into the field, and click the “Add SSH key” to complete the setup.
Hi Alfredo! You've successfully authenticated, but GitHub does not provide shell access.
ssh
command with the
-i
flag. For example,Copy that URL from the browser, go into the local
recipes
repository, and run this command:
Comment: Use your username.
origin
is a local name used to
refer to the remote repository. It could be called anything, but
origin
is a convention that is often used by default in git
and GitHub, so it’s helpful to stick with this unless there’s a reason
not to.
We can check that the command has worked by
running git remote -v
Now that authentication is setup, we can return to the remote. This command will push the changes from our local repository to the repository on GitHub:
Since Alfredo set up a passphrase, it will prompt him for it. If you completed advanced settings for your authentication, it will not prompt for a passphrase.
We can pull changes from the remote repository to the local one as well:
Pulling has no effect in this case because the two repositories are already synchronized. If someone else had pushed some changes to the repository on GitHub, though, this command would download them to our local repository.
Content
comments
If your operating system has a password manager configured,
git push
will try to use it when it needs your username and password (default behavior for Git Bash on Windows). Possible to useunset SSH_ASKPASS
.-u
is synonymous with the--set-upstream-to
option for thegit branch
command, and is used to associate the current branch with a remote branch so that thegit pull
command can be used without any arguments.git push -u origin main
once the remote has been set up.