简体   繁体   English

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

[英]How to push local changes to a remote git repository on bitbucket

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 am committing files into it. 我在Bitbucket上创建了一个存储库,并创建了一个repo的本地副本,并将文件提交到它中。 I cann't seem to push the files from my local repo to the remote repo. 我似乎无法将文件从我的本地仓库推送到远程仓库。

Here's what I'm doing: 这是我正在做的事情:

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

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 ? 关于这和简单的git push之间的区别的任何解释?

Use git push origin master instead. 请改用git push origin master

You have a repository locally and the initial git push is "pushing" to it. 你在本地拥有一个存储库,并且最初的git push正在“推送”它。 It's not necessary to do so (as it is local) and it shows everything as up-to-date. 没有必要这样做(因为它本地的)并且它显示所有内容都是最新的。 git push origin master specifies aa remote repository ( origin ) and the branch located there ( master ). git push origin master指定一个远程存储库( origin )和位于那里的分支( master )。

For more information, check out this resource . 有关更多信息,请查看此资源

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. 此外,在“git push”命令中添加-u非常有用,因为这将告诉您本地分支是在远程分支的前面还是后面。 This is shown when you run "git status" after a git fetch. 在git fetch之后运行“git status”时会显示此信息。

I'm with Git downloaded from https://git-scm.com/ and set up ssh follow 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/2518 I found that just 'git push' is working: 一旦在我的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 respond are as below: 壳牌响应如下:

$ 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

It even works for to push on merging master to gh-pages in GitHub 它甚至可以用于在GitHub中将master合并到gh-pages

git checkout gh-pages
git merge master
git push

Meaning the 2nd parameter(' master ') of the " git push " command - 含义“ git push ”命令的第二个参数(' master ') -

$ git push origin master

can be made clear by initiating " push " command from ' news-item ' branch. 可以通过从' news-item '分支启动“ push ”命令来明确。 It caused local " master " branch to be pushed to the remote ' master ' branch. 它导致本地“ master ”分支被推送到远程“ master ”分支。 For more information refer 有关更多信息,请参阅

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. 供您参考,以下是我如何验证此声明的屏幕截图。

<code>在此处输入图像说明</ code>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM