Amro Elkeran
Amro Elkeran

Reputation: 13

Create a repo from an existing project

Can someone tell me how to solve this: When I execute git init I only see (master) not (master->origin) and, when I do git branch, it returns nothing and when I try to push I get this error:

git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'github.com:BghAek/something.git'

Upvotes: 0

Views: 2174

Answers (2)

VonC
VonC

Reputation: 1324367

In order to push from your new local repository, you need to:

  • make sure you have an empty newly created GitHub repository
  • rename your local branch from master to main (check your Git version): git branch -m master main
  • execute git config --global init.defaultbranch main to use main from now on for any new local repository (since GitHub is also using main by default)
  • add the remote GitHub repository URL as remote origin:
    git remote add origin https://github.com/<me>/<myNewRepo>
  • finally push: git push -u origin main

Upvotes: 1

Code-Apprentice
Code-Apprentice

Reputation: 83527

After git init, you need to commit the code with git add . and then git commit -m "Initial commit". Then you will be able to git push if your repository has a remote that points to GitHub or some other online service.

I strongly encourage you to learn the basics of git. Pro Git is a good place to start. The first three chapters explains the fundamental concepts that you will use regularly. The remaining chapters get into more advanced concepts if you need them later.

Upvotes: 2

Related Questions