无法将提交推送到 GitHub 上新创建的存储库
Cannot push commit to a newly created repository on GitHub
我最近刚刚在 GitHub(专为我)上用我的帐户创建了一个新存储库。使用命令行,我导航到一个包含一些文件和文件夹的文件夹,我想使用命令行将这些文件和文件夹推送到在线存储库。我的在线存储库只包含一个初始提交和一个自述文件。我使用 git add --all
将所有内容添加到文件夹中并使用当前目录作为主目录我在推送时仍然遇到问题。
我尝试使用 fetch
、pull
、merge
、rebase
,然后再次使用 push
,但它不起作用。这是我所做的一部分:
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.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.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ ^C
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git fetch origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/SamuraiHub/Java
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
Counting objects: 6350, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6164/6164), done.
Writing objects: 100% (6350/6350), done.
Total 6350 (delta 534), reused 0 (delta 0)
Removing duplicate objects: 100% (256/256), done.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git merge origin master
merge: origin - not something we can merge
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git checkout master
Already on 'master'
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull --rebase
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git fetch origin master
From https://github.com/SamuraiHub/Java
* branch master -> FETCH_HEAD
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git merge origin master
merge: origin - not something we can merge
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git merge master
Already up-to-date.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ ^C
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull --rebase
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull origin master --rebase
From https://github.com/SamuraiHub/Java
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java ((ec222e4...)|AM/REBASE)
$
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java ((ec222e4...)|AM/REBASE)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java ((ec222e4...)|AM/REBASE)
$ git checkout master
Checking out files: 100% (10551/10551), done.
Previous HEAD position was ec222e4... Initial commit
Switched to branch 'master'
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master|AM/REBASE)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master|AM/REBASE)
$
除了从网站上传并使用 --force
或 -f
选项外,关于如何解决此问题的任何想法(我知道这可能不会在这里引起问题,但通常我们不应该使用它) ?
the online repository just includes an initial commit and a single readme file
那是你的问题。您的本地副本不包含该提交。
我可能会通过添加遥控器、获取 origin/master
、变基(不合并)我的本地工作来修复它,然后推送:
git remote add origin <url>
git fetch origin
git checkout master
git rebase origin/master
git push
当然,如果您希望合并也可以。但是你有一个语法错误:
$ git merge origin master
merge: origin - not something we can merge
您需要合并 origin/master
(命名远程跟踪引用的单个参数),而不是 origin master
(两个参数)。
您的 git pull
失败,因为没有 master
的跟踪信息:
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Git 不知道要获取哪个远程分支并将其合并到您的本地 master
,但您可以使用 git branch --set-upstream-to
告诉它,如错误消息所示。
请务必阅读 Git 提供的错误消息。它们可能有点密集,但确实包含有用的信息。
Any ideas on how to fix this other than uploading form the website and using the --force
or -f
option (I know it might not cause issues here but generally we should not use it)?
在这种情况下,如果您不想要 GitHub 创建的自述文件,我认为强制推送没有任何危害(尽管我建议先获取并使用 --force-with-lease
, 这不太可能让你破坏你不知道的提交)。
我最近刚刚在 GitHub(专为我)上用我的帐户创建了一个新存储库。使用命令行,我导航到一个包含一些文件和文件夹的文件夹,我想使用命令行将这些文件和文件夹推送到在线存储库。我的在线存储库只包含一个初始提交和一个自述文件。我使用 git add --all
将所有内容添加到文件夹中并使用当前目录作为主目录我在推送时仍然遇到问题。
我尝试使用 fetch
、pull
、merge
、rebase
,然后再次使用 push
,但它不起作用。这是我所做的一部分:
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.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.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ ^C
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git fetch origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/SamuraiHub/Java
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
Counting objects: 6350, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6164/6164), done.
Writing objects: 100% (6350/6350), done.
Total 6350 (delta 534), reused 0 (delta 0)
Removing duplicate objects: 100% (256/256), done.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git merge origin master
merge: origin - not something we can merge
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git checkout master
Already on 'master'
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull --rebase
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git fetch origin master
From https://github.com/SamuraiHub/Java
* branch master -> FETCH_HEAD
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git merge origin master
merge: origin - not something we can merge
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git merge master
Already up-to-date.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ ^C
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull --rebase
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master)
$ git pull origin master --rebase
From https://github.com/SamuraiHub/Java
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java ((ec222e4...)|AM/REBASE)
$
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java ((ec222e4...)|AM/REBASE)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java ((ec222e4...)|AM/REBASE)
$ git checkout master
Checking out files: 100% (10551/10551), done.
Previous HEAD position was ec222e4... Initial commit
Switched to branch 'master'
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master|AM/REBASE)
$ git push -u origin master
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': Muaz.Al.Jarhi@Gmail.com
To https://github.com/SamuraiHub/Java.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SamuraiHub/Java.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Muaz Aljarhi@MuazAljarhi-PC MINGW64 /f/muaz/Programming/Java (master|AM/REBASE)
$
除了从网站上传并使用 --force
或 -f
选项外,关于如何解决此问题的任何想法(我知道这可能不会在这里引起问题,但通常我们不应该使用它) ?
the online repository just includes an initial commit and a single readme file
那是你的问题。您的本地副本不包含该提交。
我可能会通过添加遥控器、获取 origin/master
、变基(不合并)我的本地工作来修复它,然后推送:
git remote add origin <url>
git fetch origin
git checkout master
git rebase origin/master
git push
当然,如果您希望合并也可以。但是你有一个语法错误:
$ git merge origin master merge: origin - not something we can merge
您需要合并 origin/master
(命名远程跟踪引用的单个参数),而不是 origin master
(两个参数)。
您的 git pull
失败,因为没有 master
的跟踪信息:
$ git pull There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> master
Git 不知道要获取哪个远程分支并将其合并到您的本地 master
,但您可以使用 git branch --set-upstream-to
告诉它,如错误消息所示。
请务必阅读 Git 提供的错误消息。它们可能有点密集,但确实包含有用的信息。
Any ideas on how to fix this other than uploading form the website and using the
--force
or-f
option (I know it might not cause issues here but generally we should not use it)?
在这种情况下,如果您不想要 GitHub 创建的自述文件,我认为强制推送没有任何危害(尽管我建议先获取并使用 --force-with-lease
, 这不太可能让你破坏你不知道的提交)。