如何将本地更改推送到bitbucket上的远程git存储库

时间:2011-10-07 16:24:00

标签: git bitbucket

我正在测试Git和Bitbucket。

我在Bitbucket上创建了一个存储库,并创建了一个repo的本地副本,并将文件提交到它中。我似乎无法将文件从我的本地仓库推送到远程仓库。

这就是我正在做的事情:

git clone https://me@bitbucket.org/me/test.git
cd test
touch dummy
git add dummy
git commit dummy -m "my first git commit"
git push

最后一行输出:

Everything up-to-date

当我登录Bitbucket时,我看不到我的虚拟文件。

我做错了什么?

修改

这样做有效:

 git push origin master:master

有关此与简单git push

之间区别的任何解释

4 个答案:

答案 0 :(得分:99)

改为使用git push origin master

您在本地拥有一个存储库,初始git push正在“推送”它。没有必要这样做(因为它本地的)并且它显示所有内容都是最新的。 git push origin master指定一个远程存储库(origin)和位于那里的分支(master)。

有关详细信息,请查看this resource

答案 1 :(得分:15)

这是一种避免推送尚未发布的分支的安全措施。简而言之,通过执行“git push”,只会推送服务器上已存在的具有相同名称的本地分支,或者使用localbranch:remotebranch语法推送的分支。

要将所有本地分支推送到远程存储库,请使用--all

git push REMOTENAME --all
git push --all

或指定要推送的所有分支:

git push REMOTENAME master exp-branch-a anotherbranch bugfix

此外,将-u添加到“git push”命令很有用,因为这将告诉您本地分支是在远程分支的前面还是后面。在git fetch之后运行“git status”时会显示此信息。

答案 2 :(得分:8)

我从 https://git-scm.com/ 下载Git,set up ssh按照说明https://stackoverflow.com/a/26130250/4058484的答案进行操作。

在我的Bitbucket帐户中验证生成的公钥后,并参考http://www.bohyunkim.net/blog/archives/2518上解释的步骤,我发现只有 ' git push' 正在运作:

git clone https://me@bitbucket.org/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响应如下:

$ 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://me@bitbucket.org/me/test.git 992b294..93835ca  master -> master

它甚至可以推动在GitHub中合并master to gh-pages

git checkout gh-pages
git merge master
git push

答案 3 :(得分:0)

表示“ master”命令的第二个参数('git push')-

$ git push origin master
可以通过从“ push”分支启动“ news-item”命令来使

清晰。这导致本地“ master”分支被推送到远程“ master”分支。有关更多信息,请参见

https://git-scm.com/docs/git-push

中的<refspec>
[<repository> [<refspec>…​]

的意思是“ specify what destination ref to update with what source object.

作为参考,这是我如何验证此声明的屏幕截图。

<code>enter image description here</code>