简体   繁体   English

git初始化并将本地存储库推送到远程找不到

[英]git initialize and push local repository to remote not found

I have a local directory on my Windows machine that I am trying to: 我在Windows机器上尝试执行的本地目录是:

  1. initialize using git init 使用git init
  2. add a README.md file to this repository README.md文件添加到此存储库
  3. sync this README.md file to bitbucket 将此README.md文件同步到bitbucket

However I am having trouble with the commands (steps 2. and 3.) that come after git init 但是我在git init之后遇到命令(步骤2和3.)的麻烦

I have tried this: 我已经试过了:

git init --bare tHartman3
git remote rm origin
git add -A
git remote add origin https://bitbucket.org/<username>/tHartman3

Now, I am ready to commit so I try: 现在,我准备提交,因此我尝试:

git commit -m "Created blank README.md file for tHartman3 repository"

but it gives the following error 但是它给出了以下错误

On branch master
nothing to commit, working tree clean

Then I try 然后我尝试

git push -u origin master

But this gives this error 但这给出了这个错误

remote: Not Found
fatal: repository 'https://bitbucket.org/<username>/tHartman3/' not found

When I just try 当我尝试

git push

I get this error 我得到这个错误

fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

I am not sure what is going on with this since: 我不知道这是怎么回事,因为:

  1. git remote add origin https... seemed to have worked. git remote add origin https...似乎有效。
  2. git remote -v looks good git remote -v看起来不错

I have followed instructions from here and here . 我从这里这里都遵循了指示。

Additional Notes: 补充笔记:

  • If I use git remote add origin https://bitbucket.org/<username>/tHartman3 or git remote add origin https://bitbucket.org/<username>/tHartman3.git I still get the same output for all other following commands. 如果我使用git remote add origin https://bitbucket.org/<username>/tHartman3 / git remote add origin https://bitbucket.org/<username>/tHartman3.gitgit remote add origin https://bitbucket.org/<username>/tHartman3.git我对于其他所有以下内容仍然会得到相同的输出命令。

Question

Is there something missing from here to create this local tHartman3 directory to a .git repository? 在此将本地tHartman3目录创建到.git存储库中是否缺少任何内容?

First and foremost, create the remote repository on BitBucket. 首先,在BitBucket上创建远程存储库。 You need this to be able to push to it. 您需要此功能才能继续使用它。 Pushing only works if there is something to push to on the other end. 仅当另一端有要推送的内容时,推送才有效。 Here are some off-site instructions: https://confluence.atlassian.com/bitbucket/create-and-clone-a-repository-800695642.html 以下是一些异地说明: https : //confluence.atlassian.com/bitbucket/create-and-clone-a-repository-800695642.html

Once you have a repo, you have a couple of options for how to get a working local copy of it. 有了存储库后,就可以使用两种方法获取本地工作副本。 The harder way is to make the (non-bare) repo and set up the remote manually: 较难的方法是进行(非裸机)回购并手动设置遥控器:

git init tHartman3
git remote add origin ssh://<username>@bitbucket.org/<username>/tHartman3

Keep in mind that bare repos do not have a working directory. 请记住,裸仓库没有工作目录。 They are used pretty much only for hosting a central repository since you can not actually check out any files in them. 它们几乎仅用于托管中央存储库,因为您实际上无法检出其中的任何文件。

The easier way to make a local clone is just to run the command that bitbucket shows when you click on the clone button: 进行本地克隆的更简单方法是运行在单击克隆按钮时bitbucket显示的命令:

git clone ssh://<username>@bitbucket.org/<username>/tHartman3

Now you can add your readme and run git -A . 现在,您可以添加自述文件并运行git -A Before you commit, it is usually a good idea to run git status . 在提交之前,通常最好先运行git status If you do not have any staged files, the commit will fail. 如果您没有任何暂存文件,则提交将失败。 Add any files you need manually in that case: 在这种情况下,请手动添加任何需要的文件:

git add README.md

Now the commit and push should work smoothly: 现在,提交和推送应该可以顺利进行:

git commit -m '...'
git push

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

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