推送到现有的 git repo 有 9 个步骤。
我尝试了“git push --set-upstream origin master”并得到以下错误:
C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git push --set-upstream origin master
Password for 'https://User@bitbucket.org':
To https://User@bitbucket.org/User/app.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://User@bitbucket.org/User/
app.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 merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
然后我尝试了“git pull”并得到了最新的变化:
C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git pull
Password for 'https://User@bitbucket.org':
warning: no common commits
remote: Counting objects: 344, done.
remote: Compressing objects: 100% (275/275), done.
remote: Total 344 (delta 45), reused 336 (delta 41)
Receiving objects: 100% (344/344), 15.91 MiB | 43.00 KiB/s, done.
Resolving deltas: 100% (45/45), done.
From https://bitbucket.org/User/app
* [new branch] master -> origin/master
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>
如果您希望为此分支设置跟踪信息,您可以这样做:
git branch --set-upstream-to=origin/<branch> master
我做了一个“git push”并且更改失败:
C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git push origin master
Password for 'https://User@bitbucket.org':
To https://User@bitbucket.org/User/app.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://User@bitbucket.org/User/
app.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
“git add -A”和“git commit”不起作用,因为没有什么要提交的。
C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git add -A
C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git commit
在分支 master 上没有提交,工作目录干净
“git branch --set-upstream-to=origin/master master”似乎可以解决问题。
C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git branch --set-upstream-to=origin/master master
Branch master set up to track remote branch master from origin.
但是,“git push origin master”不起作用,因为当前分支的尖端在它的远程对应物后面。
C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git push origin master
Password for 'https://User@bitbucket.org':
To https://User@bitbucket.org/User/app.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://User@bitbucket.org/User/
app.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
需要一个“git pull”来合并 repo。
C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git pull
Password for 'https://User@bitbucket.org':
Merge made by the 'recursive' strategy.
执行“git pull”后,“git push origin master”正是让同步命令在 Visual Studio git 插件中工作所需要的。
C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git push origin master
Password for 'https://User@bitbucket.org':
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 539 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To https://User@bitbucket.org/User/app.git
40d72a2..9748b8b master -> master
C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>