将 Xcode 项目添加到 github 仓库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12698482/
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
Add Xcode project to github repo?
提问by SimplyKiwi
I have JUST created a new github repo on the website. Keep in mind that I am a noob but can do basic things in terminal. Anyway, so I just created the repo on my account on github.com and didn't do a single thing to it yet.
我刚刚在网站上创建了一个新的 github 存储库。请记住,我是一个菜鸟,但可以在终端中做基本的事情。无论如何,所以我只是在我在 github.com 上的帐户上创建了 repo,但还没有做任何事情。
So all I want to do is take my Xcode project folderand upload it to my new github repo. How do I do this via terminal?
所以我想要做的就是将我的 Xcode 项目文件夹上传到我的新 github 存储库。我如何通过终端做到这一点?
回答by Dan Halperin
The best way really is to follow the instructions GitHub gives you:
最好的方法确实是按照 GitHub 给您的说明进行操作:
First, go the correct directory
首先,进入正确的目录
cd <directory of your Xcode project>
It sound like you've already got a local Git project from Xcode. If that's true, skip this code block.
听起来您已经从 Xcode 获得了一个本地 Git 项目。如果这是真的,请跳过此代码块。
git init .
git add .
git commit -s
<type in a commit message>
Last, push into your repository. The following is copied directly from my own github account, after I created a new "test" repo. Change the "dhalperi/test" part.
最后,推送到您的存储库。在我创建了一个新的“测试”存储库之后,以下内容是直接从我自己的 github 帐户中复制的。更改“dhalperi/test”部分。
Push an existing repository from the command line
git remote add origin [email protected]:dhalperi/test.git git push -u origin master
从命令行推送现有存储库
git remote add origin [email protected]:dhalperi/test.git git push -u origin master
回答by Suragch
I was just going to leave a comment above but I will also add a summarized answer. My full answer is here.
我只是想在上面发表评论,但我也会添加一个总结的答案。我的完整答案在这里。
This isn't via terminal as the question requests, but you can consider this an alternate method. It is well integrated with Xcode now, though, and not difficult to do.
这不是通过终端作为问题要求的,但您可以将其视为一种替代方法。不过,它现在与 Xcode 很好地集成在一起,并且不难做到。
Create Git repository when making a new project
创建新项目时创建 Git 存储库
See the answer I linked to above if you already have a project without a Git repository.
如果您已经有一个没有 Git 存储库的项目,请参阅我上面链接的答案。
Make a Commit
做出承诺
After making a change in your project, select Commit...from the Source Controlmenu. You will add a short commit message.
在您的项目中进行更改后,从Source Control菜单中选择Commit...。您将添加一条简短的提交消息。
Create a new GitHub repository
创建一个新的 GitHub 存储库
On the GitHubwebsite make a new repository. Call it whatever you want, but don'tadd a README or .gitignore or license yet. After creating the new repository copy the link to it.
在GitHub网站上创建一个新的存储库。随意命名,但不要添加 README 或 .gitignore 或许可证。创建新存储库后,将链接复制到它。
Add a Remote in Xcode
在 Xcode 中添加遥控器
in Xcode go to Source Control> your branch name> Configure. Then click the Remotetab > "+" button > Add remote. Fill in your repository name and address.
在 Xcode 中转到Source Control> your branch name> Configure。然后单击远程选项卡 >“ +”按钮 >添加远程。填写您的存储库名称和地址。
Push your project to GitHub
将你的项目推送到 GitHub
Go to Source Control> Push. You will have to enter your GitHub user name and password the first time.
转到源代码管理>推送。您必须第一次输入您的 GitHub 用户名和密码。
That's it. Now any time you make changes in Xcode, all you have to do is Commitand Push.
就是这样。现在,无论何时您在 Xcode 中进行更改,您所要做的就是Commit和Push。
If you didn't follow this explanation, please read thisand thisfor more detail.
Further Study
进一步研究
This is an excellent video that I recently watched that helped me understand Git and its integration with GitHub much better.
这是我最近观看的一个很棒的视频,它帮助我更好地了解 Git 及其与 GitHub 的集成。
回答by Martin Baulig
Get the Github Mac Application, you don't really need a terminal unless you want to do more fancy advanced stuff ;-)
获取 Github Mac 应用程序,除非你想做更高级的东西,否则你真的不需要终端;-)
Simply go to your project page on GitHub, then click on "Clone in Mac", this should automatically download and install it for you. You have to do this at least once to install the app and setup some required permissions.
只需转到您在 GitHub 上的项目页面,然后单击“在 Mac 中克隆”,这应该会自动为您下载并安装它。您必须至少执行一次此操作才能安装应用程序并设置一些必需的权限。
After that, you'll see the GitHub Application in your Dock, simply open it, then click on that small "+" sign at the bottom, there you'll see "Create New Repository" and "Add New Local Repository".
之后,您将在 Dock 中看到 GitHub 应用程序,只需打开它,然后单击底部的小“+”号,您将在那里看到“创建新存储库”和“添加新本地存储库”。
You can either add the repository that XCode already created for you or download one from GitHub, then open it in XCode.
您可以添加 XCode 已经为您创建的存储库,也可以从 GitHub 下载一个,然后在 XCode 中打开它。
回答by Oleh H
An easier way to do it in Xcode. You can even push only one current branch to GitHub or the whole project.
在 Xcode 中更简单的方法。你甚至可以只推送一个当前分支到 GitHub 或整个项目。
(for Xcode 11)
(对于 Xcode 11)
Just select a needed branch/(or top folder) in "Source control navigator" and right-click on it. Then select "Create remote". Or "Editor -> Create remote".
Then use your account at GitHub to create the repository. If using your GitHub account is not proposed maybe you still not add your GitHub account in Xcode -> Preferences -> Accounts
- After everything is set up. Click "Create".
- To push your project/branch to GitHub repository click "Source Control -> Push".
只需在“源代码控制导航器”中选择所需的分支/(或顶级文件夹)并右键单击它。然后选择“创建远程”。或“编辑器-> 创建远程”。
然后使用您在 GitHub 上的帐户创建存储库。如果不建议使用您的 GitHub 帐户,您可能还没有在 Xcode -> Preferences -> Accounts 中添加您的 GitHub 帐户
- 一切设置好之后。单击“创建”。
- 要将您的项目/分支推送到 GitHub 存储库,请单击“源代码管理 -> 推送”。
After that check Github. All should be there.
之后检查Github。一切都应该在那里。
回答by Vimal
if you already have a git repo on your Mac and using Xcode 9,
如果你的 Mac 上已经有一个 git repo 并使用 Xcode 9,
for xcode 9, just go to the source control tab in the navigation inspector in Xcode. right click on the master git and select create "Your project name" remote on GitHub.
对于 xcode 9,只需转到 Xcode 导航检查器中的源代码管理选项卡。右键单击主 git 并选择在 GitHub 上远程创建“您的项目名称”。
give your GitHub credentials and give a name to git repo and Xcode will create and push your code for you.
回答by mihai
a non terminal solution is to install SourceTree. Its a GUI thats super easy to use compared to the terminal. But its highly recommended to learn git commands properly.
非终端解决方案是安装SourceTree。与终端相比,它的 GUI 非常易于使用。但强烈建议正确学习 git 命令。