如何将本地更改推送到 bitbucket 上的远程 git 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7690108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to push local changes to a remote git repository on bitbucket
提问by Joel
I'm testing out Git and Bitbucket.
我正在测试 Git 和 Bitbucket。
I've created a repository on Bitbucket and have created a local copy of the repo and I am committing files into it. I can't seem to push the files from my local repository to the remote repository.
我在 Bitbucket 上创建了一个存储库,并创建了该存储库的本地副本,我正在向其中提交文件。我似乎无法将文件从本地存储库推送到远程存储库。
Here's what I'm doing:
这是我在做什么:
git clone https://[email protected]/me/test.git
cd test
touch dummy
git add dummy
git commit dummy -m "my first git commit"
git push
The final line outputs:
最后一行输出:
Everything up-to-date
And when I log on to Bitbucket I cann't see my dummy file.
当我登录到 Bitbucket 时,我看不到我的虚拟文件。
What am I doing wrong?
我究竟做错了什么?
EDIT:
编辑:
Doing this worked:
这样做有效:
git push origin master:master
Any explanations as to the difference between this and a simple git push
?
关于 this 和 simple 之间的区别的任何解释git push
?
回答by Chuck Callebs
Use git push origin master
instead.
使用git push origin master
来代替。
You have a repository locally and the initial git push
is "pushing" to it. It's not necessary to do so (as it islocal) and it shows everything as up-to-date. git push origin master
specifies a a remote repository (origin
) and the branch located there (master
).
您在本地有一个存储库,初始git push
是“推送”到它。没有必要这样做(因为它是本地的)并且它显示所有内容都是最新的。git push origin master
指定远程存储库 ( origin
) 和位于那里的分支 ( master
)。
For more information, check out this resource.
有关更多信息,请查看此资源。
回答by sunny256
This is a safety measure to avoid pushing branches that are not ready to be published. Loosely speaking, by executing "git push", only local branches that already exist on the server with the same name will be pushed, or branches that have been pushed using the localbranch:remotebranch syntax.
这是一种安全措施,可避免推送尚未准备好发布的分支。粗略地说,通过执行“git push”,只会推送服务器上已经存在的同名本地分支,或者使用 localbranch:remotebranch 语法推送的分支。
To push all local branches to the remote repository, use --all
:
要将所有本地分支推送到远程存储库,请使用--all
:
git push REMOTENAME --all
git push --all
or specify all branches you want to push:
或指定要推送的所有分支:
git push REMOTENAME master exp-branch-a anotherbranch bugfix
In addition, it's useful to add -u
to the "git push" command, as this will tell you if your local branch is ahead or behind the remote branch. This is shown when you run "git status" after a git fetch.
此外,添加-u
到“git push”命令很有用,因为这将告诉您本地分支是在远程分支之前还是之后。当您在 git fetch 后运行“git status”时会显示此信息。
回答by Chetabahana
I'm with Git downloaded from https://git-scm.com/and set up sshfollow to the answer for instructions https://stackoverflow.com/a/26130250/4058484.
我使用Git从下载https://git-scm.com/和设置ssh后续的答案说明https://stackoverflow.com/a/26130250/4058484。
Once the generated public key is verified in my Bitbucket account, and by referring to the steps as explaned on http://www.bohyunkim.net/blog/archives/2518I found that just 'git push'is working:
在我的 Bitbucket 帐户中验证生成的公钥后,通过参考http://www.bohyunkim.net/blog/archives/2518上解释的步骤,我发现只有'git push'正在工作:
git clone https://[email protected]/me/test.git
cd test
cp -R ../dummy/* .
git add .
git pull origin master
git commit . -m "my first git commit"
git config --global push.default simple
git push
Shell respond are as below:
Shell响应如下:
$ git push
Counting objects: 39, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (39/39), done.
Writing objects: 100% (39/39), 2.23 MiB | 5.00 KiB/s, done.
Total 39 (delta 1), reused 0 (delta 0)
To https://[email protected]/me/test.git 992b294..93835ca master -> master
It even works for to push on merging master to gh-pagesin GitHub
它甚至适用于在 GitHub 中将master合并到 gh-pages
git checkout gh-pages
git merge master
git push
回答by Park JongBum
Meaning the 2nd parameter('master
') of the "git push
" command -
意思是master
“ git push
”命令的第二个参数(' ')-
$ git push origin master
can be made clear by initiating "push
" command from 'news-item
' branch. It caused local "master
" branch to be pushed to the remote 'master
' branch. For more information refer
可以通过push
从 ' news-item
' 分支启动“ ”命令来明确。它导致本地“ master
”分支被推送到远程“ master
”分支。有关更多信息,请参阅
https://git-scm.com/docs/git-push
https://git-scm.com/docs/git-push
where <refspec>
in
其中,<refspec>
在
[<repository> [<refspec>…?]
is written to mean "specify what destination ref to update with what source object.
"
写成“ specify what destination ref to update with what source object.
”的意思
For your reference, here is a screen capture how I verified this statement.
供您参考,这是我如何验证此声明的屏幕截图。