I create a repository in Github and on my local machine I ran the code:
git init
git branch -m main
git remote add origin https://github.com/.../Project.git
git push -u origin main
Instead of using master
branch I want to use main
branch.
When running git push -u origin main
I get the error:
failed to push some refs to 'https://github.com/.../Project.git'
What am I doing wrong?
CodePudding user response:
Don't think you're doing anything necessarily wrong, persay. Git just doesn't know where to begin tracking between your local and the remote, because its a new repo (I assume). And you haven't initialised the remote yet. Try:
git pull --rebase origin main
git push origin main
Maybe do a git push -u origin main
first. And make a copy of your source directory, just in case anything goes wrong so you don't lose your uncommitted code.
Whenever I am making a new repo on github, I use their website to create the repo first, then do a git clone to put the empty repo into my home directory. That way there is none of this nonsense when I go to make my first commit!
CodePudding user response:
Is your local repo empty?
In this case, you need to add a file and commit it.
1. Run notepad test.txt (Windows) or touch test.txt (Mac)
2. Save the file.
3. git add .
4. git commit -m "Initial commit"
5. git push -u origin main