banner



How To Create Git Repository In Windows

so I thought I'd leave this here to help everyone else who was having similar issues:

                mkdir myDirName    #this is the name of your directory cd /myDirName git init touch readME.md   #this is to create an initial file to push git commit -m "enter commit message here" git remote add origin git@github.com:YOUR_USERNAME/myDirName.git  curl -u USERNAME:PASSWORD https://api.github.com/user/repos -d '{"name":"myDirName"}' #this will create the repo in github.  # if you haven't generated and SSH key for github access then follow these steps, otherwise you're good to push your shit to github. eval $(ssh-agent -s) ssh-keygen -t rsa -b 4096 -C "email@yourdomain.com" #this should be your github email address ## you'll be prompted to a couple of times. Press enter for the first prompt. choose a passphrase for the second prompt, or press enter twice for no passphrase ssh-add ~/.ssh/id_rsa   #this is your private key cat ~/.ssh/id_rsa.pub   # copy the output of this command. this is your SSH public key curl -u USERNAME:PASSWORD https://api.github.com/user/keys -d '{"title":"KEY_NAME", "key":"YOUR_RSA_PUBLIC_KEY_HERE"}'   #the value you copied earlier and your keyname. I recommend using a combination of machine name and app (My-laptop (Git CLI) git push -u origin master                              

This worked for me at the time of writing with slight modifications.

If you are using Microsoft Windows please, download Git for Windows before proceeding and use Git Bash (it's comes with Git for Windows) for the command line operations.

If you haven't generated SSH keys for GitHub access perform the following steps as outlined in the original comment:

eval $(ssh-agent -s)
ssh-keygen -t rsa -b 4096 -C "email@yourdomain.com" #this should be your github email address
you'll be prompted to a couple of times. Press enter for the first prompt. choose a passphrase for the second prompt, or press enter twice for no passphrase
ssh-add ~/.ssh/id_rsa #this is your private key
cat ~/.ssh/id_rsa.pub # copy the output of this command. this is your SSH public key

When I performed the following step stated in the original comment:

curl -u USERNAME:PASSWORD https://api.github.com/user/keys -d '{"title":"KEY_NAME", "key":"YOUR_RSA_PUBLIC_KEY_HERE"}' #the value you copied earlier and your keyname. I recommend using a combination of machine name and app (My-laptop (Git CLI)

I got the following error:

              "message": "Not Found", "documentation_url": "https://developer.github.com/v3/users/keys/#create-a-public-key"                          

This means the public key must be saved to our account first before we can perform any operations with curl to GitHub. To the best of my current knowledge (at the time of writing) that's why the last curl command generated an error because there was no public key attached to our account. Here is what we'll do.

Go to GitHub website (make sure you are logged in) then proceed to the SSH and GPG keys settings then click New SSH key

Create New SSH key

Next, you need to add the key manually to GitHub via the form as shown in the image below.

Enter title and SSH public key

Save the key. Then go back to your command line and perform the following steps as outlined in the original comment:

mkdir myDirName #this is the name of your directory
cd /myDirName
git init
touch readME.md #this is to create an initial file to push
git commit -m "enter commit message here"
git remote add origin git@github.com:YOUR_USERNAME/myDirName.git

curl -u USERNAME:PASSWORD https://api.github.com/user/repos -d '{"name":"myDirName"}' #this will create the repo in github.

You should know that if you have 2FA turned on for your account you will have to use a Personal Access Token in place of the password, therefore, the curl command will be:

curl -u USERNAME:PERSONAL_ACCESS_TOKEN https://api.github.com/user/repos -d '{"name":"myDirName"}' #this will create the repo in github.

This last command will save your Personal Access Token or password in your Bash history. If I find a way to prevent this I will update this comment.

The repo is currently empty because there is nothing in the README.md file, we need to add something to it. The following will do:

echo "# test-repo" >> README.md

Then you need to add the modified README.md file to the staging area.

git add README.md

You can add a commit message :

git commit -m "Update README.md"

Then push it with the following command:

git push -u origin master

That's it. Hope this helps someone.


If you are using Microsoft Windows Command line, please have a look at the following comment by @Amruth-Smaragdine.

This comment assumes that you have done the previous steps before running the command to create the repo.

Mind you, some commands in the previous steps won't work on the Microsoft Windows Command line e.g touch. But if I find a way around this, I'll update this comment.

I am not sure how I missed entering "\" in my earlier command.
Here is the correct command: curl -u Amruth-Smaragdine https://api.github.com/user/repos -d "{\"name\": \"testrepo\"}"
Extremely sorry for the confusion. Please accept my apologies.
In MS Windows the double quotes have to be shared with the help of a "\", which is normally used for escape sequence in normal coding procedures.

Reference Screenshots:
GIT - Creation of Repo from Command Line in MS Windows 10

GIT - Creation of Repo from Command Line in MS Windows 10 - 02

Note: I have identified something that I ignored earlier. In my earlier comment, I have not included the text with <> insert code option, hence the "\" was not getting previewed.

GIT - Creation of Repo from Command Line in MS Windows 10 - 03

GIT - Creation of Repo from Command Line in MS Windows 10 - 04

Thanks a ton. You made me realize my mistakes.

How To Create Git Repository In Windows

Source: https://gist.github.com/alexpchin/dc91e723d4db5018fef8

Posted by: paddockthadvice.blogspot.com

0 Response to "How To Create Git Repository In Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel