How to Remotely create a Github Repo

Wesley Huber
3 min readNov 25, 2023

--

Stop making a new repo from Github’s website!

You can do it in one line on the CLI, right from VSCode (where you probably started your project) then push to the repo, this is how (using https):

git remote add origin https://{git_username}:{personal_access_token}@github.com/{git_username}/{name_of_repo}.git

There are 3 variables here that are wrapped in ‘{ }’ let’s dive into each of the 3 variables so you can replace them with your own values.

git_username

This one should be easy, if you don’t already have a Github account then create one or login to your Github account here: https://github.com/
Your username for logging into Github and the username on your profile is what you are looking for, mine is wbaxterh.

personal_access_token

This variable is less obvious to access, I will guide you to how to get there.

  1. Click on your profile image on the upper right hand of the screen — that should slide out a navigation drawer like this:

2. From here, click on settings

3. Scroll down on your profile settings and you should see “Developer settings” on the right hand side

4. From here click on “Personal Access Tokens” then “Tokens (classic)” and then click Generate new token, “Generate new token (classic)”

5. Now we are creating the PAT (personal access token). here you can set an expiration. For security it is advised to add an expriation, if you are selecting no expiration make sure you are securely storing your token.

6. Check the scope of your token, for adding repos you only need to select the “repo” but if you also want to delete repos I would also select the “delete repo” checkbox as you scroll down.
7. Generate Token — that should give you the personal_access_token we need to use in our CLI command. Copy that and paste it in a file somewhere safe or even an Environment or System Variable.

name_of_repo

This one is super easy. Just think of a good name for your repo. Ideally, it should match the name of the project folder you are working in.

Now you should be ready to fill in all the variables for the CLI

git remote add origin https://{git_username}:{personal_access_token}@github.com/{git_username}/{name_of_repo}.git

Then you will just add and commit your files for your project

git add .
git commit -m 'first commit'

Then push set the origin to the master branch and push

git push --set-upstream origin master

I’m on a Macbook M1 and this is what it looked like for me:

Now you can save your command with the personal_access_token to create more repos in the future, and it will be faster than going to the Git website, then cloning that repo and bringing your project into that repo.

Let me know if this helped, or if you have other suggestions for faster or smarter development!

If you enjoyed this article please consider Buying Me a Coffee

Peace!
-Wes

--

--