1

I am a GitHub newbe. I've created a project on my computer in a folder named "SpettroCorpoNero", which contains a file "SpettroCorpoNero.ipynb". Now I would like to initializate it into my GitHub account. For this purpose I wrote on my git (which is on Linux) the following lines of code:

git init (which should initializate my project) git status (Which shows in red the new files I would like to replicate on my GitHub account) git add SpettroCorpoNero.ipynb (which is the list of file to put in the "basket") git commit -m "That's BlackBodySpectrum" (That looks like another basket to put in) git push 

And the code looks like working up to the second last line of code. Than the following message of error I've received

fatal: No configured push destination. Either specify the URL from the command-line or configure a remote repository using git remote add <name> <url> and then push using the remote name git push <name> 

In order to sort it out, different attempts I've done, such as following that push with my nickname (which is Stefanovic80), as suggested in the message of error. But I failed in all of them and now I fill confused and disoriented.

Is there anyone who could fix this issue, please?

1
  • the issue is that, you have initialized a project and are tracking it through git (not to be confused with github which hosts (stores and maintains) repositories). for you to push this project to github, you will have to create a repository in github and add that to your project, that is what the git remote add means. once you add the repository details you will be able to push it using the git push command. Commented Apr 22, 2021 at 20:11

2 Answers 2

2

As the command says, you need to tell it where to push to, the default name is origin, the url is the same as the clone url of the repo.

git remote add origin https://GitHub.com/account/repo.git 

You need to have a base repository on GitHub to push your repo into first using this route.

If you have the github-cli installed you can create the target repo and set the remote in one go by calling

gh repo create 

from your local git repository. It will create the repo on GitHub and set up your local settings so you can push your repo straight after.

See also:

Sign up to request clarification or add additional context in comments.

Comments

1

Simply, you just need to set up your remote. If you go to your remote repository (which is most likely empty), you'll see a URL which you can copy, which looks something like:

https://github.com/my-username/my-repo-name

Then, in command line, run the command

git remote add origin https://github.com/my-username/my-repo-name

You can substitute origin with whatever you like, but that will be the name of your remote connection.

Finally, you need to push main (or whatever the branch may be named) to the remote origin:

git push -u origin main

4 Comments

Thanks, it looks like a further step, but still the job is not done. In fact, I created a repository named BlackBodySpectrum, I wrote "git remote add origin github.com/stefanovic80/BlackBodySpectrum" and Git was happy. But when I wrote "git push -u origin main" another message of error appeared, which I report here error: src refspec main does not match any. error: failed to push some refs to 'github.com/stefanovic80/BlackBodySpectrum'
You created the remote repo with a readme and/or ignore file. So now your local and remote are out of sync. You can use -force on your push to overrule that once.
The command line "git push --force origin master" did the job. Now I have a main branch, which is still empy (except the readme file) and a "master branch", which is the active one and contains the file "SpettroCorpoNero.ipynb". I suppose that my next step is to merge them in one branch only
Just delete one of the 2 branches.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.