8

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.

Community
  • 1
  • 1
Dr. Essen
  • 603
  • 2
  • 9
  • 25

4 Answers4

12

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 :)

lightup
  • 634
  • 8
  • 18
  • Also, I want to know whether I have to create a branch on Github website or can be created in local via terminal and update in Github? – Dr. Essen Jun 04 '16 at 08:02
  • 1
    Yes. You can create a branch on Github website. As well as create a branch locally and push or update it in Github. – lightup Jun 05 '16 at 12:36
3
  • 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
Shravan40
  • 8,922
  • 6
  • 28
  • 48
  • As I said, I want everything to do from terminal. Even making a repository, and I dont want to make a new repo. I want my cplusplus_learn to make repo. Please read the complete question. Thanks. – Dr. Essen Jun 04 '16 at 07:29
  • 3
    @Ac3 You need to manually create an empty repo first via github website interface. Git and Github is a different application and you can't create new empty repo in github via git. – dieend Jun 04 '16 at 07:33
  • Ok, I was thinking whether there is a way to create repo in github via git. Thanks for clarifying. – Dr. Essen Jun 04 '16 at 07:45
2

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!

0

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

wozza xing
  • 51
  • 1
  • 1