Dr. Essen
Dr. Essen

Reputation: 621

Create Existing Directory as Repository in GIT

I have a directory say cplusplus_learn and my username is apex_user (say) in git. Inside cplusplus_learn, there are some files and directories which I am practising C++ language. I want to make a repository of same name as cplusplus_learn and push every thing in GITHUB website. Can someone please explain me the complete steps for doing that. I went through various links but totally confused. Mostly says that there is already repo is made.

convert-existing-non-empty-directory-into-a-git-working-directory

github-error-repository-not-found-fatal

Note: All things I want to do from terminal.

$ cd cplusplus_learn
$ git init .
$ git commit -m 'My first commit'
$ git remote add origin https://github.com/apex-user.git
fatal: remote origin already exists.
$ git push -u origin master
fatal: repository 'https://github.com/apex-user/' not found

Given above is what I tried. I know there is something wrong but I can't figure that out.

Upvotes: 9

Views: 16508

Answers (4)

Abhishek Dvs
Abhishek Dvs

Reputation: 31

Updated for 2023: This should be able to help you.

In your local folder through the command line, execute these list of commands:

  1. git init
  2. git add . && git commit -m "<Your commit name here>"
  3. git remote add origin <Github repository URL> (you can get it from your Github, and if you do not have a repository, you can create that with the help of gh repo create command or on the Github website).
  4. git remote -v
  5. git push --set-upstream origin master

You're all set!

Upvotes: 3

wozza xing
wozza xing

Reputation: 61

You could use the git hub cli https://cli.github.com/manual/gh_repo_create

Upvotes: 0

lightup
lightup

Reputation: 674

First you need to login in to your github account and create a repository with the name cplusplus_learn

All things I want to do from terminal. Just as you have already described. From your description, it seems that you have a wrong remote url already set so you need to update or reset it as shown below

$ cd cplusplus_learn
$ git init 
$ git commit -m 'My first commit'
$ git remote set-url origin https://github.com/apex-user/cplusplus_learn.git
$ git push -u origin master

Hopefully this should work. Thanks :)

Upvotes: 13

Shravan40
Shravan40

Reputation: 9908

  • Add your SSH Key into Github profile setting.
  • Create a repository on Github. For example (RepoName)
  • Navigate into your project directory cplusplus_learn.
  • Initialize the git git init.
  • git remote add origin https://github.com/apex-user/RepoName.git
  • git add -A
  • git commit -m "Message you would like to put"
  • git push origin master

Upvotes: 3

Related Questions