Git: push error: error: failed to push some refs to

Keywords: git github Ubuntu ssh

Reference link: https://help.github.com/en/articles/dealing-with-non-fast-forward-errors

Report errors:

 ! [rejected]master -> master (fetch first)
error: failed to push some refs to 'https://github.com/rtczza/IPC.git'

You want to upload the fork folder and the files in its directory to github.

Use commands:

1,git add fork/

2,git commit -m "add fork"

3,git remote add origin https://github.com/rtczza/IPC.git

4,git push -u origin master

In step 4, the error is reported as follows:

root@ubuntu:/home/chemi/neo/ken/git# ls
fork
root@ubuntu:/home/chemi/neo/ken/git# git add fork/
root@ubuntu:/home/chemi/neo/ken/git# git commit -m "add fork"
[master (root-commit) c23e5f9] add fork
 2 files changed, 63 insertions(+)
 create mode 100755 fork/test
 create mode 100644 fork/test.c
root@ubuntu:/home/chemi/neo/ken/git# git remote add origin https://github.com/rtczza/IPC.git
root@ubuntu:/home/chemi/neo/ken/git# git push -u origin master
Username for 'https://github.com': rtczza
Password for 'https://rtczza@github.com': 
To https://github.com/rtczza/IPC.git
 ! [rejected]master -> master (fetch first)
error: failed to push some refs to 'https://github.com/rtczza/IPC.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
root@ubuntu:/home/chemi/neo/ken/git# 

Solution:

First use the git pull origin master command, then git push.

As shown below

root@ubuntu:/home/chemi/neo/ken/git# git pull origin master
From https://github.com/rtczza/IPC
 * branchmaster -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 01_fork | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 01_fork
root@ubuntu:/home/chemi/neo/ken/git# 
root@ubuntu:/home/chemi/neo/ken/git# 
root@ubuntu:/home/chemi/neo/ken/git# git push -u origin master
Username for 'https://github.com': rtczza
Password for 'https://rtczza@github.com': 
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 3.78 KiB | 0 bytes/s, done.
Total 7 (delta 0), reused 0 (delta 0)
To https://github.com/rtczza/IPC.git
   e34c88d..f354fde  master -> master
Branch master set up to track remote branch master from origin.
root@ubuntu:/home/chemi/neo/ken/git#

Then you can see the uploaded file in github.

1. User name and password need to be input in the process of uploading.

2. Global configuration, already configured.

3. The warehouse was built in advance. (nonsense)

4. ssh is also configured.

Posted by js_280 on Fri, 04 Oct 2019 16:25:22 -0700