Home > OS >  git cannot push to existing repo
git cannot push to existing repo

Time:06-23

I have a GitHub repo energys_arduino_max485_mqtt_autoconnect_ec400, but I have problem in push the file to this repo

(base) Mac-Pro energys_arduino_max485_mqtt_autoconnect_ec400 % git remote add origin https://github.com/SamuelXiot/energys_arduino_max485_mqtt_autoconnect_ec400.git
error: remote origin already exists.
(base) Mac-Pro energys_arduino_max485_mqtt_autoconnect_ec400 % git branch -M main
(base) Mac-Pro energys_arduino_max485_mqtt_autoconnect_ec400 % git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/SamuelXiot/energys_arduino_max485_mqtt_autoconnect_ec400.git.'
(base) Mac-Pro energys_arduino_max485_mqtt_autoconnect_ec400 % git remote remove origin
(base) Mac-Pro energys_arduino_max485_mqtt_autoconnect_ec400 % git remote add origin https://github.com/SamuelXiot/energys_arduino_max485_mqtt_autoconnect_ec400.git
(base) Mac-Pro energys_arduino_max485_mqtt_autoconnect_ec400 % git branch -M main
(base) esp32@Arthurs-Mac-Pro energys_arduino_max485_mqtt_autoconnect_ec400 % git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/SamuelXiot/energys_arduino_max485_mqtt_autoconnect_ec400.git'
(base) Mac-Pro energys_arduino_max485_mqtt_autoconnect_ec400 % git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/SamuelXiot/energys_arduino_max485_mqtt_autoconnect_ec400.git'
(base) Mac-Pro energys_arduino_max485_mqtt_autoconnect_ec400 % git pull --rebase
remote: Repository not found.
fatal: repository 'https://github.com/SamuelXiot/energys_arduino_max485_mqtt_autoconnect_ec400.git/' not found
(base) Mac-Pro energys_arduino_max485_mqtt_autoconnect_ec400 % git push
error: src refspec refs/heads/main does not match any
error: failed to push some refs to 'https://github.com/SamuelXiot/energys_arduino_max485_mqtt_autoconnect_ec400.git'

why I cannot push to GitHub??

CodePudding user response:

It seems like you're trying to upload all of your code at once to the empty repo you've made on github's site. It also seems you've already run git init

You need to first commit all of your changes with git add . then git commit -m "comment you choose" so that you have something to push. It's possible that you've made a new branch, you don't need a branch in this situation.

git add .
git commit -m "first commit"
git remote add origin https://github.com/user/repo.git
git push

CodePudding user response:

Finally found the solution, I need to update the GitHub account in Mac first.

Need to delete all account credential

$ git credential-osxkeychain erase
host=github.com
protocol=https
> [Press Return]

create a PAT

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

then update the git login in terminal

(base) -Mac-Pro 485_mqtt_autoconnect % git push origin Username for 'https://github.com': SamuelXiot Password for 'https://[email protected]': Enumerating objects: 18, done. Counting objects: 100% (18/18), done. Delta compression using up to 8 threads Compressing objects: 100% (12/12), done. Writing objects: 100% (18/18), 3.22 KiB | 1.07 MiB/s, done. Total 18 (delta 1), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (1/1), done. To https://github.com/SamuelXiot/485_mqtt_autoconnect.git

  • [new branch] master -> master (base) -Mac-Pro 485_mqtt_autoconnect %

then normal again.

thanks all for the help.

  • Related