在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

时间:2022-10-30 13:58:31

The Git integration in XCode 4 is very welcome however it seems to be a bit flaky when it comes to dealing with remote repositories. For clarity I'm using OS X version 10.6.7 and XCode 4.0.2 (4A2002a).

XCode 4中的Git集成是非常受欢迎的,但是在处理远程存储库时,它似乎有点不稳定。为了清晰起见,我使用了OS X version 10.6.7和XCode 4.0.2 (4A2002a)。

If I create a new XCode 4 Project and accept the option to create a local Git repository, all is well. I can commit locally and that's great.

如果我创建一个新的XCode 4项目并接受创建本地Git存储库的选项,那么一切都很好。我可以在本地提交,这很好。

When I want to push the new project to GitHub I want to add a remote repository and push my local changes up to GitHub. I can add a GitHub repository to XCode 4 as a new Repository in the Organizer window but there's no method of setting it as a remote repository for my existing project.

当我想将这个新项目推到GitHub时,我想添加一个远程存储库,并将本地更改推到GitHub。我可以将一个GitHub存储库添加到XCode 4,作为一个新的存储库,但是没有方法将它设置为我现有项目的远程存储库。

So I switch to using git commands in Terminal.

所以我切换到在终端使用git命令。

git remote add origin https://<username>@github.com/<organization>/<repository>.git

If I then go back to XCode 4 and try to use

如果我回到XCode 4,试着使用它。

File -> Source Control -> Push...

文件->源代码控制->推送…

then the Choose the repository to which to push changes. dialog appears listing the origin remote repository. There's a yellow indicator saying that Authentication is required, which is fine as I've not been able to enter my credentials yet for HTTPS. However when I click 'Push' and it tries to push the changes it says "The operation could not be performed because access to the repository 'origin' is denied."

然后选择要推动更改的存储库。对话框出现在源远程存储库中。有一个黄色指示符表示需要进行身份验证,这很好,因为我还没有能够为HTTPS输入我的凭据。然而,当我点击“Push”时,它会尝试推动修改,它说“无法执行操作,因为无法访问存储库的来源”。

A dialog prompting me for my username and password then appears with my pre-filled out so it must be reading this correctly from the local repository's config.

提示我输入我的用户名和密码的对话框会出现在我的预填文件中,所以必须正确地从本地存储库的配置中读取它。

When I enter my password XCode 4 then crashes with the following error

当我输入密码XCode 4时,会出现以下错误。

ASSERTION FAILURE in /SourceCache/IDEKit/IDEKit-303/Framework/Classes/SourceControl/IDESourceControlOperationInfo.m:59
Details:  Message sent to invalidated object: <IDESourceControlPushOperationInfo, 0x200bd2a80>. Backtrace for invalidation:
 (null)
Object:   <IDESourceControlPushOperationInfo: 0x200bd2a80>
Method:   -invalidate
Thread:   <NSThread: 0x200020700>{name = (null), num = 1}
Hints:   None

If I restart XCode an origin repository has been added to the Repositories browser in Organizer and I can see the master branch on GitHub so I know the credentials are right without me changing anything.

如果我重新启动XCode,就会将原始存储库添加到组织者的储存库浏览器中,我可以看到GitHub上的主分支,这样我就知道凭证是正确的,没有我改变任何东西。

Has anyone found a reliable way of using XCode 4 with GitHub starting with a local project first?

有没有人找到一种可靠的方法来使用GitHub使用XCode 4,先从本地项目开始?

If I clone an existing GitHub repository with an XCode project in it, open it with XCode 4 then even though the first Push seems to fail, the 2nd push did then work. So maybe starting from absolute scratch with XCode 4 creating the repository for me isn't the best pattern (until they improve the Git tooling in a later version of XCode 4).

如果我在其中使用XCode项目克隆一个现有的GitHub存储库,那么在第一个Push似乎失败的情况下,即使第一个Push似乎失败了,第二个Push也会成功。因此,从绝对的scratch开始,用XCode 4创建存储库并不是最好的模式(直到他们在XCode 4的后期版本中改进了Git工具)。

EDIT WITH FURTHER DETAILS OF ONE WORKAROUND

This example only really applies to the first project you're adding to a GitHub repository. As such I think you're better off with the following steps, bearing in mind there still seem to be some XCode 'gotchas' in this solution.

这个示例只适用于添加到GitHub存储库中的第一个项目。因此,我认为您最好遵循以下步骤,记住在这个解决方案中似乎仍然存在一些XCode 'gotchas'。

  1. List item
  2. 列表项
  3. 'Connect to a repository' from Welcome to XCode dialog.
  4. 从欢迎到XCode对话框“连接到存储库”。
  5. Use GitHub SSH URL for Location
  6. 使用GitHub SSH URL来定位。
  7. Give it a name (RepositoryName)and Clone to a directory
  8. 给它一个名称(储存库名称)和克隆到一个目录。
  9. 1st attempt appears to fail even though contents are downloaded
  10. 第一次尝试似乎失败了,即使下载了内容。
  11. Try Again and it works.
  12. 再试一次,成功了。
  13. There is now a new Repository defined in the Organizer window with its origin set to the GitHub remote SSH URL.
  14. 现在,在组织者窗口中定义了一个新的存储库,其源设置为GitHub远程SSH URL。
  15. Create a New Project within the directory you just cloned into but DO NOT tick the 'Create local git repository for this project' option.
  16. 在您刚刚克隆到的目录中创建一个新项目,但是不要在“为这个项目的选择创建本地git存储库”中勾选。
  17. Do initial commit to local Git repository.
  18. 对本地Git存储库进行初始提交。
  19. Try Source Control -> Push and XCode 4 fails with 'The operation could not be performed because access to the repository RepositoryName was denied. Check username and password'
  20. 尝试源代码控制-> Push和XCode 4失败,因为无法执行操作,因为无法访问存储库储存库名称。检查用户名和密码的
  21. Try Source Control -> Push and XCode 4 pops up the remote Repository dialog again but this time has detected a remote Repository called origin. Next to it there's a yellow ball and 'Authentication required'.
  22. 尝试源代码控制——> Push和XCode 4再次弹出远程存储库对话框,但这次检测到一个名为origin的远程存储库。在它旁边有一个黄色的球和“认证要求”。
  23. Clicking 'Push' again caused the remote Push to work.
  24. 点击“Push”再次导致远程推送工作。

One thing I've spotted and not managed to work out yet is that the response messages back from GitHub with the checkin hash value and any messages seem to get reported in XCode Log navigator as Push failures, even though the Push is successful as far as GitHub is concerned.

我发现并没有解决的一件事是,从GitHub返回的响应消息与checkin哈希值和任何消息似乎都在XCode日志导航器中被报告为Push故障,尽管在GitHub上的Push是成功的。

Anyone else have a better solution?

还有人有更好的解决办法吗?

3 个解决方案

#1


88  

I think I found the Xcode way to push a existing project to GitHub or any other remote repository!

我认为我找到了将现有项目推给GitHub或任何其他远程存储库的Xcode方法!

Preconditions

  • I assume that you have a project created by Xcode 4 with a local git repository.
  • 我假设您有一个由Xcode 4创建的项目,它包含一个本地git存储库。
  • You created an empty remote git repository (I call it RemoteRepository in in the following example)
  • 您创建了一个空的远程git存储库(在下面的示例中,我将其称为RemoteRepository)

Push it to remote

  1. Open the Organizer in Xcode an go to the Repositories tab

    打开Xcode中的组织者,进入储存库选项卡。

  2. At first click on Remotes and then on "Add Remote"

    首先点击Remotes,然后点击“添加远程”

    在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  3. Enter a Remote Name and the Location of your remote repository and click on create

    输入远程名称和远程存储库的位置并单击create。

    在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  4. Then select your project and open File -> Source Control -> Push ...

    然后选择您的项目和打开文件->源代码控制->推送…

    在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  5. Select your remote repository and wait until it is connectable! Look for the Create in the brackets.

    选择您的远程存储库,并等待它是可连接的!在括号中查找Create。

    在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  6. Now your old project is published to GitHub

    现在你的旧项目被发布到GitHub上。

    在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

I hope it will works for you also! In my case it works with every remote git repository.

我希望它对你也有用!在我的例子中,它使用每个远程git存储库。

Please contact me on twitter if something unclear or wrote in bad English!

如果有什么不清楚的或用不好的英文写的,请在推特上联系我!

#2


2  

I've done this successfully using an ssh connection (which looks like git@github.com:<username>/<project>.git). It authenticates the user based on an SSH public key, which you can generate on the command line--lots of docs about that at github in the "help" section.

我已经成功地使用了ssh连接(它看起来像git@github.com: / .git)。它基于SSH公钥对用户进行身份验证,您可以在命令行上生成这样的密钥——在“帮助”部分的github上有很多这样的文档。

#3


2  

Xcode 6.2 (and possibly 6.x) changed things around. There no longer is a Repositories tab in the Organizer. Here's how to do it with the newer Xcodes.

Xcode 6.2(可能是6.x)改变了周围的事物。在管理器中不再有一个储存库选项卡。下面是如何使用更新的xcode。

To add a project with a local git repository to GitHub, this is what you do:

要向GitHub添加一个本地git存储库的项目,您可以这样做:

  1. Go to the Source Control menu, elect your project and select Configure:
  2. 进入源代码控制菜单,选择您的项目并选择Configure:

在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  1. You'll see:
  2. 你会看到:

在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  1. Select the Remotes tab, and press the "+" in the lower left corner. Select Add Remote.
  2. 选择Remotes选项卡,并在左下角按“+”键。选择Add远程。

在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  1. Type in a name for the remote repository, and type in the URL for your remote repository. Make sure you've created this remote repository already, and if on GitHub, make are you specify that this is an existing project, and not a new one.
  2. 输入远程存储库的名称,并输入远程存储库的URL。确保您已经创建了这个远程存储库,如果在GitHub上,您可以指定这是一个已经存在的项目,而不是一个新的项目。

在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  1. You're almost done. Go to the Source Control menu and select Push. You will then see the name of the repo you used in the last step, something like "simplest/master"; press the Push button.
  2. 几乎就要完成了。进入源控制菜单并选择Push。然后,您将看到在最后一步中使用的repo的名称,类似于“最简单/主”;按下按钮。

Done.

完成了。

#1


88  

I think I found the Xcode way to push a existing project to GitHub or any other remote repository!

我认为我找到了将现有项目推给GitHub或任何其他远程存储库的Xcode方法!

Preconditions

  • I assume that you have a project created by Xcode 4 with a local git repository.
  • 我假设您有一个由Xcode 4创建的项目,它包含一个本地git存储库。
  • You created an empty remote git repository (I call it RemoteRepository in in the following example)
  • 您创建了一个空的远程git存储库(在下面的示例中,我将其称为RemoteRepository)

Push it to remote

  1. Open the Organizer in Xcode an go to the Repositories tab

    打开Xcode中的组织者,进入储存库选项卡。

  2. At first click on Remotes and then on "Add Remote"

    首先点击Remotes,然后点击“添加远程”

    在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  3. Enter a Remote Name and the Location of your remote repository and click on create

    输入远程名称和远程存储库的位置并单击create。

    在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  4. Then select your project and open File -> Source Control -> Push ...

    然后选择您的项目和打开文件->源代码控制->推送…

    在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  5. Select your remote repository and wait until it is connectable! Look for the Create in the brackets.

    选择您的远程存储库,并等待它是可连接的!在括号中查找Create。

    在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  6. Now your old project is published to GitHub

    现在你的旧项目被发布到GitHub上。

    在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

I hope it will works for you also! In my case it works with every remote git repository.

我希望它对你也有用!在我的例子中,它使用每个远程git存储库。

Please contact me on twitter if something unclear or wrote in bad English!

如果有什么不清楚的或用不好的英文写的,请在推特上联系我!

#2


2  

I've done this successfully using an ssh connection (which looks like git@github.com:<username>/<project>.git). It authenticates the user based on an SSH public key, which you can generate on the command line--lots of docs about that at github in the "help" section.

我已经成功地使用了ssh连接(它看起来像git@github.com: / .git)。它基于SSH公钥对用户进行身份验证,您可以在命令行上生成这样的密钥——在“帮助”部分的github上有很多这样的文档。

#3


2  

Xcode 6.2 (and possibly 6.x) changed things around. There no longer is a Repositories tab in the Organizer. Here's how to do it with the newer Xcodes.

Xcode 6.2(可能是6.x)改变了周围的事物。在管理器中不再有一个储存库选项卡。下面是如何使用更新的xcode。

To add a project with a local git repository to GitHub, this is what you do:

要向GitHub添加一个本地git存储库的项目,您可以这样做:

  1. Go to the Source Control menu, elect your project and select Configure:
  2. 进入源代码控制菜单,选择您的项目并选择Configure:

在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  1. You'll see:
  2. 你会看到:

在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  1. Select the Remotes tab, and press the "+" in the lower left corner. Select Add Remote.
  2. 选择Remotes选项卡,并在左下角按“+”键。选择Add远程。

在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  1. Type in a name for the remote repository, and type in the URL for your remote repository. Make sure you've created this remote repository already, and if on GitHub, make are you specify that this is an existing project, and not a new one.
  2. 输入远程存储库的名称,并输入远程存储库的URL。确保您已经创建了这个远程存储库,如果在GitHub上,您可以指定这是一个已经存在的项目,而不是一个新的项目。

在XCode 4中,如何将远程GitHub存储库添加到现有的本地项目中?

  1. You're almost done. Go to the Source Control menu and select Push. You will then see the name of the repo you used in the last step, something like "simplest/master"; press the Push button.
  2. 几乎就要完成了。进入源控制菜单并选择Push。然后,您将看到在最后一步中使用的repo的名称,类似于“最简单/主”;按下按钮。

Done.

完成了。