How to connect Xcode 9 and GitHub?

2020-02-12 12:07发布

问题:

I am part of a group of computer science students building their first project in Swift. We have attempted to connect GitHub with the XCode git configurations so we can all edit one project through pushing and pulling commits. We have little to no prior experience implementing GitHub with native applications such as XCode and online articles have not explained how we can create a project in XCode and connect it to GitHub so we can push and pull to Github and edit a 'master project' that we all have access to.

The closest we have gotten is doing XCode -> Preferences -> Accounts and adding new GitHub accounts(ours). However, the project does not show up when we open our GitHubs.

Does anyone know how we can make a collaborative project with GitHub and achieve the above goals? Please frame your answer in the context of us being totally unfamiliar with the process.

Thanks much!

回答1:

You can put the project on GitHub from Xcode 9's source control navigator. Start by opening the source control navigator by choosing View > Navigators > Show Source Control Navigator.

Select the Remotes folder, right-click, and choose Create Remote on GitHub. On Xcode 10 the menu item is Create "ProjectName" Remote. A sheet similar to the following will open:

Since you added your GitHub account to Xcode, you can choose the account from the Account menu. If you hadn't added your GitHub account, you would choose Add a GitHub Account and enter your account name and password.

Give your repository a name and add a description if you want. Choose Public for the visibility unless you have a GitHub plan (paid or student) that allows private repositories. Click the Create button and your project will be on GitHub for the other people in your group to clone. They can clone the project by choosing Source Control > Clone.



回答2:

Create a repository in GitHub (preferably private if you have a paid account) after you create the project head to terminal and navigate to project by:

cd  path_to_project

then run these commands

git init

git commit -m "first commit"

git remote add origin https://github.com/UserName/RepoName.git

git push -u origin master

After that you can commit and push from source control menu in Xcode, then every student make a checkout so he can add his tasks and push.