Skip to content

Instantly share code, notes, and snippets.

@alexpchin
Last active December 11, 2024 07:54
Show Gist options
  • Save alexpchin/dc91e723d4db5018fef8 to your computer and use it in GitHub Desktop.
Save alexpchin/dc91e723d4db5018fef8 to your computer and use it in GitHub Desktop.
Create a new repository on the command line

Setting up a new Git Repo

##Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:alexpchin/<reponame>.git
git push -u origin master

##Push an existing repository from the command line

git remote add origin git@github.com:alexpchin/<reponame>.git
git push -u origin master
@Habib0x0
Copy link

Habib0x0 commented Apr 25, 2024

First of all use github cli

gh

Authenticate github to use command line

gh auth login
 

Once you successfully authenticated , now you can create your repo from command line

gh repo create repo-name --flag

Here the repo-name could be the repo name you want to use and --flag is if you want to make the repo private or public if you want to make it public use --public for private --private
for example this will create myrepo as public repository
gh repo create myrepo --public
once you created the repo, now you can initiate git in your current directory project using

git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:username/<reponame>.git
git push -u origin master 

to add the rest of your files use

git add .
git commit -m "Upload rest of files"
git push

if you face any error , you might need to check which branch is in use , you can change the branch using the following command

git branch -M main 

now you can push the file to your repo

git push -u origin main 

@mann9776
Copy link

curl -u USERNAME:ACCESS_TOKEN https://api.github.com/user/repos -d '{"name":"myDirName"}'

This command worked for me. Thanks a lot @nettcaster87. I was facing issue in authentication and could not be able to create repository using windows command line.

@chased316
Copy link

First of all use github cli

gh

Authenticate github to use command line

gh auth login
 

Once you successfully authenticated , now you can create your repo from command line

gh repo create repo-name --flag

Here the repo-name could be the repo name you want to use and --flag is if you want to make the repo private or public if you want to make it public use --public for private --private for example this will create myrepo as public repository gh repo create myrepo --public once you created the repo, now you can initiate git in your current directory project using

git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:username/<reponame>.git
git push -u origin master 

to add the rest of your files use

git add .
git commit -m "Upload rest of files"
git push

if you face any error , you might need to check which branch is in use , you can change the branch using the following command

git branch -M main 

now you can push the file to your repo

git push -u origin main 

This is actually so insane I wrote a cli util just to make repos>
https://github.com/chased316/makerepo

@jamiecropley
Copy link

You don't even need to login / authorise every single time, just set up SSH key on computer, then do gh repo create nameofrepo then go to the url it generates and it automatically tells you all the command lines to do, but as you mentioned git add . is the only thing to change really.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment