Reputation: 145
I am a bit curious about pushing a locally created folder(project) to Github. Is it possible? Please let me explain what I have already done. I am using Git for Windows on Windows 8.1 64-bit.
$ git init fresh-project Initialized empty Git repository in D:/MyDev/projects/fresh-project/.git/
2.
$ ls fresh-project/
**$ cd fresh-project**
**ls**
**$ git status**
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
**Used $ code hipster.txt**
To create the file by opening VSCode and added some text.
**$ git status**
On branch master
No commits yet
Untracked files: (use "git add ..." to include in what will be committed) hipster.txt
nothing added to commit but untracked files present (use "git add" to track)
**$ git add hipster.txt**
**$ git status**
On branch master
No commits yet
Changes to be committed: (use "git rm --cached ..." to unstage) new file: hipster.txt
**$ git commit**
hint: Waiting for your editor to close the file... [main 2020-04-12T09:45:20.658Z] update#setState idle [main 2020-04-12T09:45:50.660Z] update#setState checking for updates [main 2020-04-12T09:45:50.870Z] update#setState idle [master (root-commit) b427f7c] Adding new file with hipster ipsum This was done with VSCode in 12th April 2020 15:20 1 file changed, 1 insertion(+) create mode 100644 hipster.txt
11.
$ git status On branch master nothing to commit, working tree clean
After the 11th step I want to push the whole local repository to Github.com. I haven't created a
repository in Github with the name of 'fresh-project'.
What else do I have to do to make this to happen?
Thanks and regards, Chiranthaka
Upvotes: 0
Views: 1332
Reputation: 46
As already mentioned, when you create a new repository on Github, it displays steps on how you push an existing local project/repository from command line:
git remote add origin https://github.com/username/yourremoterepo.git
git push -u origin master
Furthermore, you can also use -v as below to showcase the URLs git has stored to be used for reading/writing to that remote repo:
git remote -v
origin https://github.com/username/yourremoterepo (fetch)
origin https://github.com/username/yourremoterepo (push)
If this isn't pointing to your required project (fresh-project), there's a high likelihood that the project was never created on Github. Or the steps to create the remote weren't followed correctly.
Assuming you're a beginner to git as myself, I would recommend to start reading the Pro-git book. It can be found here. For reference on working with remotes, see section 2.5
Upvotes: 0
Reputation: 784
You should have searched on github for this. It's easy all you need to do is first add files and commit then add remote repo url and push to github
$ git remote add origin https://github.com/user/yourremoterepo.git
If you want to create repo using command line you need to use Github api for that You need an access token and curl to POST repo
curl -H "Authorization: token ACCESS_TOKEN" --data '{"name":"Reponame"}' https://api.github.com/user/repos
Upvotes: 1