如何在 Xcode 中配置 Git 以使用 BitBucket

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9870632/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:20:11  来源:igfitidea点击:

How do I configure Git in Xcode to work with BitBucket

iphonexcodegitbitbucket

提问by TheLearner

I have a project which I have been on for ages which is not connected to any source code repository.

我有一个我已经从事多年的项目,它没有连接到任何源代码存储库。

I want to start using BitBucket now, however I am not sure how to go about it. I have created a project in BitBucket.

我现在想开始使用 BitBucket,但是我不知道如何去做。我在 BitBucket 中创建了一个项目。

Should I now clone and check out in Xcode or should I add a repository in xcode. Anyone have any idea?

我现在应该在 Xcode 中克隆并签出,还是应该在 xcode 中添加一个存储库。任何人有任何想法?

I have tried cloning using the URL from bitbucket but it just comes back with an error in Xcode

我曾尝试使用 bitbucket 中的 URL 进行克隆,但它只是在 Xcode 中出现错误

采纳答案by Tom

As of 2017, xCode now automatically creates repositories for new projects. To push to a new BitBucket repo, go to 'Source Control' > 'Commit...' in xCode and make your first local commit.

截至 2017 年,xCode 现在会自动为新项目创建存储库。要推送到新的 BitBucket 存储库,请转到 xCode 中的“源代码管理”>“提交...”并进行您的第一次本地提交。

Next open a terminal and navigate to to the top-level directory of your project. If you ls -ain here you should see the .git/directory has been created. In the same directory, add your remote repo with the following (replace with your username/team name and repo name):

接下来打开一个终端并导航到项目的顶级目录。如果你ls -a在这里你应该看到.git/目录已经创建。在同一目录中,使用以下内容添加您的远程仓库(替换为您的用户名/团队名称和仓库名称):

git remote add origin https://[email protected]/USERNAME/REPO_NAME.git

Go back into xCode, go to 'Source Control' > 'Push...'. You'll be prompted to enter your BitBucket password. Press OK and you're done! Source control commands will now be working within xCode.

返回 xCode,转到“源代码管理”>“推送...”。系统会提示您输入 BitBucket 密码。按确定,你就完成了!源代码控制命令现在将在 xCode 中工作。

回答by Zinan Xing

I've met the same problem and here's how I solved it:

我遇到了同样的问题,这是我解决它的方法:

  1. (Assume your project is not already under local source control) Create a new project under LOCAL source control (Please note that adding remote source control at this stage may not be successful)

  2. Make this new project a clone of your old project - drag files, add frameworks, etc.

  3. In menu "Source Control" -> -> "Configure " In the new window, click on "Remotes" -> "+" -> "Add Remote"

  4. "Source Control" -> "Commit"

  5. Select "push to remote" at the left bottom corner

  6. Click "Commit"

  7. Check on BitBucket website to see if it's actually pushed to it

  1. (假设你的项目还没有在本地源码控制下)在本地源码控制下新建一个项目(请注意,此阶段添加远程源码控制可能不会成功)

  2. 使这个新项目成为旧项目的克隆 - 拖动文件、添加框架等。

  3. 在菜单“Source Control”->->“Configure”在新窗口中,点击“Remotes”->“+”->“Add Remote”

  4. “源代码控制”->“提交”

  5. 选择左下角的“push to remote”

  6. 点击“提交”

  7. 检查 BitBucket 网站,看看它是否真的推送给它

回答by gzge

I did that through command line and it is fairly straightforward.

我是通过命令行完成的,而且相当简单。

  1. create a new repo on bitbucket
  2. assuming your xcode project is not under local git version control yet
  3. go to command line, cd to your xcode project directory, and the follow the bitbucket doc: https://confluence.atlassian.com/display/BITBUCKET/Import+code+from+an+existing+project

    git init
    git remote add origin [email protected]:<user_id>/<repo>.git
    git add .
    git commit -am 'init commit'
    git push -u origin master
    
  4. go back to xcode and you should be able to interact with bitbucket through xcode from this point on

  1. 在 bitbucket 上创建一个新的 repo
  2. 假设您的 xcode 项目尚未受本地 git 版本控制
  3. 转到命令行,cd 到您的 xcode 项目目录,然后按照 bitbucket 文档:https://confluence.atlassian.com/display/BITBUCKET/Import+code+from+an+existing+project

    git init
    git remote add origin [email protected]:<user_id>/<repo>.git
    git add .
    git commit -am 'init commit'
    git push -u origin master
    
  4. 回到 xcode,从现在开始,您应该能够通过 xcode 与 bitbucket 进行交互

回答by Dan

Using the following URL structure

使用以下 URL 结构

https://[email protected]/accountname/reponame.git

(Taken from here) did the job for me

(取自此处)为我完成了这项工作

回答by VonC

It is easier to:

更容易:

  • create your local Git repo through XCode and add your code there
  • in command line, add the remote 'origin' toward your BitBucket repo, along with your ssh credentials (in ~/.ssh/config): see
  • do at least one "git push myrepo origin master" to initiate the first push
  • 通过 XCode 创建您的本地 Git 存储库并在那里添加您的代码
  • 在命令行中,将远程“来源”添加到您的 BitBucket 存储库中,以及您的 ssh 凭据(在 中~/.ssh/config):请参阅
  • 至少做一个“ git push myrepo origin master”来启动第一次推送

回答by Bobby

This link helped me, I will also copy and paste the instructions in case the link goes away.

这个链接对我有帮助,如果链接消失,我也会复制和粘贴说明。

http://sketchytech.blogspot.com/2016/02/send-xcode-project-to-bitbucket.html

http://sketchytech.blogspot.com/2016/02/send-xcode-project-to-bitbucket.html

Sending a non-git Xcode Project to BitBucket from GitHub is the most popular place to host your repos but if you are looking for a free service for teams that are 5 members or less then take a look at BitBucket. Here are instructions for moving a local Xcode project onto BitBucket. (Note: if you opted for a local Git when you created your project you should be able to skip steps 3 and 4.)

将非 git Xcode 项目从 GitHub 发送到 BitBucket 是最流行的托管存储库的地方,但如果您正在为 5 人或以下的团队寻找免费服务,请查看 BitBucket。以下是将本地 Xcode 项目移动到 BitBucket 的说明。(注意:如果您在创建项目时选择了本地 Git,您应该可以跳过第 3 步和第 4 步。)

-Sign-up for BitBucket and create a repo

- 注册 BitBucket 并创建一个 repo

-In Xcode go to Source Control menu

- 在 Xcode 中转到源代码管理菜单

-Select "Create a working copy ...."

- 选择“创建工作副本......”

-Select project and press Create in dialog window

- 选择项目并在对话窗口中按创建

-Return to Source Control menu and select -> Configure ...

- 返回源代码管理菜单并选择 -> 配置...

-Click "Remotes" tab

- 单击“远程”选项卡

-Press add "+"

-按添加“+”

-Copy and paste the https address you see at the top right of your repo page into the remote location in Xcode

- 将您在 repo 页面右上角看到的 https 地址复制并粘贴到 Xcode 中的远程位置

-Go to Source Control menu and select Push... to upload the project

- 转到 Source Control 菜单并选择 Push... 上传项目

Pushing code updates to BitBucket Now you have it set up whenever you want to push code to the project:

将代码更新推送到 BitBucket 现在,只要您想将代码推送到项目,就可以设置它:

-Go to Source Control menu and select Commit

- 转到源代码管理菜单并选择提交

-Write a commit note and uncheck anything not to be included in the commit

- 写一个提交说明并取消选中任何不包含在提交中的内容

-Return to Source Control menu and select push

-返回源控制菜单并选择推送

-Select the correct branch and Push

- 选择正确的分支并推送

Pulling code down from BitBucket repo To get code provided by others down from BitBucket:

从 BitBucket 存储库中提取代码 从 BitBucket 中获取其他人提供的代码:

-Go to Source Control menu and select Pull.

- 转到源代码管理菜单并选择拉。

回答by Roberto Ardila Garcia

I use SourceTree and Xcode 6.1 and in my case I first create a repository on bitbucket, then I clone my repository on an empty folder (using SourceTree or via command line) then when you create the new project on XCode in that folder, you can commit push and pull normally from XCode

我使用 SourceTree 和 Xcode 6.1,在我的情况下,我首先在 bitbucket 上创建一个存储库,然后将我的存储库克隆到一个空文件夹(使用 SourceTree 或通过命令行),然后当您在该文件夹中的 XCode 上创建新项目时,您可以从 XCode 正常提交推送和拉取

回答by CaptainBleuten

I found this youtube videoand it helped me a lot, used this Atlasssian helpfor ssh authentication, and encountered an Xcode problem for which the solution can be found in this page.

我找到了这个 youtube 视频,它对我帮助很大,使用这个 Atlasssian 帮助进行 ssh 身份验证,并遇到了 Xcode 问题,可以在此页面中找到解决方案。