git cannot push to existing repo - github

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??

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

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://SamuelXiot#github.com':
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

Why cant I upload any new project to GitHub?

I have been going at the endlessly all semester. I was able to add project from my prior year in school but have been unable to push and new projects to my repository.
I have tried deleting my key credentials via my key access chain.
I have created a new GitHub account and tried using that one.
I have deleted repositories started from scratch over and over.
I have read question on question and tried following multiple different answers on here.
What I wouldn't give to understand what is going on and why nothing seems to allow me to push a project anymore.
The most current attempt was going back to my original GitHub account.
I created a brand new repository.
I created a new folder and copied my simple python project into it and saved.
error: remote origin already exists.
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git remote rm origin
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git remote rm upstream
error: No such remote: 'upstream'
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git remote add origin https://github.com/stephanieBrandon/GuessARandomNumberGame.git
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/stephanieBrandon/GuessARandomNumberGame.git'
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % ls -a
. .. guess_a_random_number.py
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /Users/stephaniebrandon/Documents/GitHubPortfolio/Python/GuessARandomNumberGame/pythonGame/.git/
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git remote add origin https://github.com/stephanieBrandon/GuessARandomNumberGame.git
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/stephanieBrandon/GuessARandomNumberGame.git'
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % ls -a
. .. .git guess_a_random_number.py
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 pythonGame % git status
On branch master
I am hoping there is just some simple thing I am missing, if someone could explain and help me out it would be much appreciated.
Stephanie, your local branch name is "master", not "main" as you can see from the "git status" output.
If you try "git push origin master", it should work.
You dont have branch main, you have branch master. 😊
Try:
git push origin master
You need to have some commits before pushing your repository to Github.
Moreover, your local default branch name is master, so you have to use git push -u origin master instead of git push -u origin main
$ ls
guess_a_random_number.py
$ git init
Initialized empty Git repository in /Users/stephaniebrandon/Documents/GitHubPortfolio/Python/GuessARandomNumberGame/pythonGame/.git/
$ git add .
$ git commit -m "initial commit"
$ git remote add origin https://github.com/stephanieBrandon/GuessARandomNumberGame.git
$ git push -u origin master # not main

Github error: failed to push some refs to github.com

I have installed the git ,created repository , then I have tried to push from vs code to github repository with cmd
git push -u origin main
Git say error: failed to push some refs to 'github.com:loobj126/boredape-dapp-bj.git''
What's the problem?
https://github.com/loobj126/boredape-dapp-bj
i ve few approach yet still not resolve
https://komodor.com/learn/how-to-fix-failed-to-push-some-refs-to-git-errors/
Latest input :
after initialize
[2022-04-20T08:44:06.669Z] Validating found git in: C:\Program Files\Git\cmd\git.exe
[2022-04-20T08:44:06.796Z] Using git 2.35.3.windows.1 from C:\Program Files\Git\cmd\git.exe
[2022-04-20T10:45:43.723Z] > git init [128ms]
[2022-04-20T10:45:44.399Z] > git rev-parse --git-dir [72ms]
[2022-04-20T10:45:44.403Z] Open repository: c:\Users\loobj\boredape-dapp-bj
[2022-04-20T10:45:44.606Z] > git fetch [197ms]
[2022-04-20T10:45:44.676Z] > git symbolic-ref --short HEAD [119ms]
[2022-04-20T10:45:44.765Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/master refs/remotes/master [85ms]
[2022-04-20T10:45:44.872Z] > git remote --verbose [99ms]
[2022-04-20T10:45:44.888Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [119ms]
[2022-04-20T10:45:45.019Z] > git config --get commit.template [122ms]
[2022-04-20T10:45:45.040Z] > git config --local branch.master.github-pr-owner-number [121ms]
[2022-04-20T10:45:45.300Z] > git symbolic-ref --short HEAD [101ms]
[2022-04-20T10:45:45.385Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/master refs/remotes/master [80ms]
[2022-04-20T10:45:45.490Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [101ms]
[2022-04-20T10:45:45.507Z] > git remote --verbose [115ms]
[2022-04-20T10:45:45.589Z] > git config --get commit.template [76ms]
Click push
[2022-04-20T10:59:18.763Z] > git push boredape-dapp-bj master [153ms]
[2022-04-20T10:59:18.763Z] error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/loobj126/boredape-dapp-bj.git'
[2022-04-20T11:00:41.028Z] > git fetch [141ms]
[2022-04-20T11:00:41.220Z] > git symbolic-ref --short HEAD [68ms]
[2022-04-20T11:00:41.286Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/master refs/remotes/master [63ms]
[2022-04-20T11:00:41.380Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [91ms]
[2022-04-20T11:00:41.394Z] > git remote --verbose [102ms]
[2022-04-20T11:00:41.485Z] > git config --get commit.template [84ms]
Solution 1: for error: src refspec master does not match any.
All you need to perform is git commit with a proper message and then do git push to the remote origin to avoid any errors.
mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .
git commit -m "initial commit"
git push origin master
Solution 2 – First, check what refs you have, and once you find that, make a git push to the specific remote branch.
# To get all the ref
git show-ref
# replace with your branch name according to ref
git push origin HEAD:<branch>
this worked for me.
To fix the error, go on and run following commands:
git pull --rebase origin main
git push -u origin main
If the first command above runs successfully, you should get a response that says: Successfully rebased and updated refs/heads/main.
The second command pushes your local repo's current state to the remote branch.
ref: https://www.freecodecamp.org/news/error-failed-to-push-some-refs-to-how-to-fix-in-git/

Error failed to push some refs to git commit

I'm trying to upload a navbar file to git, but it keeps saying that some references couldn't be pushed, and I don't know where I'm going wrong.
PS E:\navbar> git init
Initialized empty Git repository in E:/navbar/.git/
PS E:\navbar> git add README.md
fatal: pathspec 'README.md' did not match any files
PS E:\navbar> git commit -m "first commit"
Author identity unknown
*** Please tell me who you are.
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got '신은영#DESKTOP-0T69V65.(no
PS E:\navbar> git remote add origin https://github.com/kimdohyeon0811/learnit
PS E:\navbar> git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/kimdohyeon0811/learnit'
PS E:\navbar> git remote -v
origin https://github.com/kimdohyeon0811/learn_css.git (fetch)
origin https://github.com/kimdohyeon0811/learn_css.git (push)
PS E:\navbar> git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/kimdohyeon0811/learn_css.git'
PS E:\navbar>
You have two separate problems here, and they're related. The first is that you've failed to configure your the name and email used in your commits, and so Git is refusing to commit any changes. The second is that because you have no commits in your repository, trying to push the branch main or master doesn't work, because it doesn't exist. That's the message that you're getting when you see “src refspec
does not match any.”
You need to configure your name and email, which are stored in user.name and user.email. Note that user.name is a personal name, not a username. So, for example, someone might run these commands:
$ git config --global user.name "Pat Doe"
$ git config --global user.email pdoe#example.com
Then, once you've made those changes, you can commit and it should succeed. Once you have commits, you can push them.
Note that if you want to use main as the default branch but your repository is using master, you can run git branch -m main and that will rename the branch. If you want to do that, do it before you push.

Cannot push onto github

I want to pysh my project to a github repository called luna.git:
I followed the instructions
echo “# luna” >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/raouiyounes/luna.git
git push -u origin master
But I get this error
error: src refspec master does not match any.
error: impossible de pousser des rĂ©fĂ©rences vers ‘https://github.com/raouiyounes/luna.git’
Maybe you just need to commit.
Try this:
git add .
git commit -m "initial commit"
git push origin master
You can do :
git push origin HEAD:branch-name

Github: ERROR: Repository not found. fatal: The remote end hung up unexpectedly (different)

This is my code:
$ git clone https://github.com/Perrydu/jekyll-plumbious.git Perrydu.github.com
$ cd Perrydu.github.com
$ git remote set-url origin git#github.com:Perrydu/Perrydu.github.com.git
$ git push origin master
The terminal:
Last login: Sat Oct 6 19:54:15 on ttys000
Dus-MacBook-Pro:~ Perry$ $ git clone https://github.com/Perrydu/jekyll-plumbious.git Perrydu.github.com
-bash: $: command not found
Dus-MacBook-Pro:~ Perry$ git clone https://github.com/Perrydu/jekyll-plumbious.git Perrydu.github.com
Cloning into Perrydu.github.com...
remote: Counting objects: 34, done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 34 (delta 3), reused 30 (delta 3)
Unpacking objects: 100% (34/34), done.
Dus-MacBook-Pro:~ Perry$ cd Perrydu.github.com
Dus-MacBook-Pro:Perrydu.github.com Perry$ git remote set-url origin git#github.com:Perrydu/Perrydu.github.com.git
Dus-MacBook-Pro:Perrydu.github.com Perry$ git push origin master
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly
Dus-MacBook-Pro:Perrydu.github.com Perry$
jekyll-plumbious.git is my project like jekyll-bootstrap.
I assume that you're following the steps described here:
http://jekyllbootstrap.com/
It looks from your GitHub account as if the problem is that you've created a repository with the name perrydu.github.com, but the repository you're referring to with the URL of origin is Perrydu.github.com. The names of GitHub repositories are case sensitive, so I would go into the GitHub admin interface for the lowercase-named repository (perrydu.github.com) and rename it to Perrydu.github.com.
Then, after a couple of minutes, the push command you tried before should work.