Uploading code to GitHub using Xcode

Source: Internet
Author: User

Almost all iOS programmers have been on GitHub looking for open source libraries, and indeed, there are plenty of great open source libraries on GitHub for everyone to learn. But how do you upload code to github in Xcode?

(Install git before you start, and here's how it's clear: http://git.oschina.net/progit/1-starts. html)

Begin

First we create a new project, remember to tick create Git repository on:

This means that using source Control, Git repository is created by default in the project. After the project is built, you will see this information in the right sidebar stating that the source Control is enabled

If you are not using source Control, this is the case:

Now that we have the source control enabled in the project, we can use Git to manage the engineering version.

But what if we want to add GIT functionality to a project that does not have git enabled? We can use the command line to turn on this feature, create a new project, do not tick create Git repository on, we do not turn on source control, and then we manually create Git management, as shown in:

Yibantekiimac-3:usegit yiban$ Cd/users/yiban/documents/ios_dev/manualgitdemoyibantekiimac-3:manualgitdemo YiBan$ git initinitialized empty git repository in/users/yiban/documents/ios_dev/manualgitdemo/.git/

Use

Git init

To initialize an empty git repository, now use the Ls-la command to view all files in the directory (including hidden files)

Total 16
drwxr-xr-x   7 yiban  staff   238   5 12 16:10 .drwxr-xr-x  52 YiBan  staff  1768   5 12 16:06&NBSP, .... [email protected]  1 yiban  staff  6148  5 12  16:10 . Ds_storedrwxr-xr-x   9 yiban  staff   306  5 12  16:06 .gitdrwxr-xr-x  12 yiban  staff   408  5  12 16:06 ManualGitDemodrwxr-xr-x   5 YiBan  staff    170  5 12 16:06 manualgitdemo.xcodeprojdrwxr-xr-x   5 yiban   staff   170  5 12 16:06 manualgitdemotests 

We now see two hidden files in addition to three files. Ds_store and. Git,.ds_store are files generated by OS X that contain The Location property in the folder ,. Git is enabled by the source control auto-generated directory, and then uses GIT status to view the current status:

yibantekiimac-3:manualgitdemo yiban$ git statuson branch  masterinitial commituntracked files:   (use  "Git add <file> ..."   to include in what will be committed)     . ds_store    manualgitdemo.xcodeproj/    manualgitdemo/     ManualGitDemoTests/nothing added to commit but untracked files  present  (use  "Git add"  to track) 

Indicates that the initialization was successful and the files that were not being traced were displayed. But we don't want to. Ds_store also joins git, because that file is of no use to us, we can ignore it, by creating a new file named. Gitignore, and then using a text editor to enter the following information:

# Xcode?. Ds_store?*/build/*?*.pbxuser!default.pbxuser *.mode1v3!default.mode1v3 *.mode2v3!default.mode2v3 *.perspectivev3! Default.perspectivev3 xcuserdataprofile *.moved-aside Deriveddata.idea/*.hmap

Save to the project folder so that we have one more. gitignore file in our catalog, and then we use the git status command to view the current status:

Yibantekiimac-3:manualgitdemo yiban$ git statuson branch masterinitial commituntracked files: (use "git add <file>. .. "To include in what'll be committed). Gitignore Manualgitdemo.xcodeproj/manualgitdemo/manualgitdemotest S/nothing added to commit but untracked files present (use "Git add" to track)

See here already No. Ds_store, stating that Gitignore has ignored the. Ds_store. Can now be submitted, using the

git Add.

This command first adds the file to the staging area but has not yet committed to view the status:

yibantekiimac-3:manualgitdemo yiban$ git statuson branch masterinitial  commitchanges to be committed:   (use  "Git rm --cached <file  to unstage)     new file:   .gitignore     new file:   manualgitdemo.xcodeproj/project.pbxproj    new  file:   ManualGitDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata     new file:   manualgitdemo/appdelegate.h    new file:    ManualGitDemo/AppDelegate.m    new file:    manualgitdemo/base.lproj/main.storyboard    new file:   manualgitdemo/ images.xcassets/appicon.appiconset/contents.json    new file:    Manualgitdemo/images.xcassets/launchimage. launchimage/contents.json    new file:   manualgitdemo/ manualgitdemo-info.plist    new file:   manualgitdemo/ Manualgitdemo-prefix.pch    new file:   manualgitdemo/viewcontroller.h     new file:   ManualGitDemo/ViewController.m     New file:   manualgitdemo/en.lproj/infoplist.strings    new file:    ManualGitDemo/main.m    new file:    manualgitdemotests/manualgitdemotests-info.plist    new file:    manualgitdemotests/manualgitdemotests.m    new file:    Manualgitdemotests/en.lproj/infoplist.strings

now commit, use git commit-m "initail" command, the content inside the quotation marks is the comment that is submitted, can write anything:

yibantekiimac-3:manualgitdemo yiban$ git commit -m  "Initial" [master  (root-commit )  83bbefc] initial 17 files changed, 803 insertions (+)  create  mode 100644 .gitignore create mode 100644 manualgitdemo.xcodeproj/ project.pbxproj create mode 100644 manualgitdemo.xcodeproj/project.xcworkspace/ contents.xcworkspacedata create mode 100644 manualgitdemo/appdelegate.h create  mode 100644 manualgitdemo/appdelegate.m create mode 100644 manualgitdemo/ base.lproj/main.storyboard create mode 100644 manualgitdemo/images.xcassets/ appicon.appiconset/contents.json create mode 100644 manualgitdemo/images.xcassets/ launchimage.launchimage/contents.json create mode 100644 manualgitdemo/ Manualgitdemo-info.plist create mode 100644 manualgitdemo/manualgitDemo-prefix.pch create mode 100644 manualgitdemo/viewcontroller.h create mode  100644 manualgitdemo/viewcontroller.m create mode 100644 manualgitdemo/en.lproj /infoplist.strings create mode 100644 manualgitdemo/main.m create mode  100644 manualgitdemotests/manualgitdemotests-info.plist create mode 100644  manualgitdemotests/manualgitdemotests.m create mode 100644 manualgitdemotests/en.lproj/ Infoplist.strings

Then check the status:

Yibantekiimac-3:manualgitdemo yiban$ git Statuson branch masternothing to commit, working directory clean

OK, the current workspace is clean and the code has been submitted. We can either submit the code with Xcode, or we can commit it with a command, but we can do more with the command line. Use Xcode to view the history of the submission, Source control->history:

Add Project to GitHub

First you must have a GitHub account, no words to register one, and also create ssh,github using a public-private key to ensure that the communication process with your computer is secure.

The SSH creation process is like this:

1. Enter CD ~/.ssh in the command line, then LS, see what files are in this folder , if there is id_rsa.pub or id_dsa.pub (the name may be different), you already have SSH keys, you can add it to your account

2. If not, you can get the error message "No such file or directory", which is generated by the command:

Ssh-keygen-t rsa-c "YOUR EMAIL"

Fill in your email address, then you will be asked to fill in the password, the SSH keys will be generated, the SSH keys will be added to your GitHub account, you can find the SSH keys in the account settings, and then fill in the title and key, now, Your SSH key is tied to your GitHub account.

Go to your profile and create a new repository (top right of the page) to enter some information:

Enter repository name and description, and then select Create, and you will see a link to repository:

Assign the link down, go to Xcode, Source control-> First->configure ..., then choose remotes:

ADD remote, enter name (your project name) and address (previous link address), then source Control->push, select the newly created link, push~

Now refresh the GitHub homepage, your project has been added successfully!


Uploading code to GitHub using Xcode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.