Use Xcode to upload code to GitHub

Source: Internet
Author: User
Tags ssh account

Almost all iOS programmers go to GitHub to find open-source class libraries. Indeed, there are a lot of excellent open-source class libraries on GitHub for everyone to learn. But how can I upload code to GitHub in Xcode?

 

(Install git before you start. The specific method is as follows: http://git.oschina.net/progit/1- .html)

Start

First, Create a project. Remember to check Create git repository on:

This indicates that if Source Control is used, git repository is created in the project by default. After the project is created, the information is displayed on the right sidebar, indicating that Source Control is enabled.

If Source Control is not used, it is as follows:

Now we have enabled Source Control in the project, so that you can use git to manage the project version.

But what if we want to add the git function to a project without git enabled? You can use the command line to enable this function to Create a new project. If you do not select Create git repository on, the Source Control is not enabled, and you can 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 ..-rw-r--r--@  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

In this case, we can see that there are two hidden files besides the three files ,. DS_Store and. git ,. DS_Store is a file generated by OS X. It contains the location attribute in the folder ,. git enables the directory automatically generated by Source Control, 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)

It indicates that the initialization is successful and an untracked file is displayed. However, we do not want. DS_Store is also added to git, because the file is of no use to us, we can ignore it. The specific method is to create a new file named. gitignore, and then enter the following information in the Text Editor:

# Xcode

.DS_Store

*/build/*

*.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdataprofile
*.moved-aside DerivedData.idea/*.hmap

Save it to the project folder, so we have an extra. gitignore file in our directory. Then we can 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 will be committed)    .gitignore    ManualGitDemo.xcodeproj/    ManualGitDemo/    ManualGitDemoTests/nothing added to commit but untracked files present (use "git add" to track)

No. DS_Store exists, indicating that. gitignore has ignored. DS_Store. You can submit it now. Use

git add .

This command First adds the file to the temporary storage area, but it has not been submitted. Check 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

Submit now. Run the git commit-m "Initail" command. The content in the quotation marks is the comments submitted. You can write anything at will:

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

Check the status again:

YiBantekiiMac-3:ManualGitDemo YiBan$ git statusOn branch masternothing to commit, working directory clean

All right, the current workspace is clean, and the code has been submitted. You can use Xcode to submit code or command to submit code, but you can do more with the command line. You can use Xcode to view submitted historical records, Source Control-> History:

 

Add a project to GitHub

First, you must have a GitHub account. If you do not have one, you must register one and create an SSH account. GitHub uses a public/private key to ensure secure communication with your computer.

The SSH creation process is as follows:

1. Enter cd ~ in the command line ~ /. Ssh, and then ls to see which files are in this folder. If id_rsa.pub or id_dsa.pub is available (the name may be different), it means you already have SSH keys, you can add it to your account.

2. If not, you will get the error message "No such file or directory". In this case, you can generate it by using the command:

ssh-keygen -t rsa -C "YOUR EMAIL"

Enter your email address there, and you will be asked to enter the password. At this time, the SSH keys will be generated, with SSH Keys, you can add it to your GitHub account. Find the SSH keys option in account settings and enter the title and key. Now, your SSH Key is bound to the GitHub account.

Go to the personal homepage and create a repository (in the upper-right corner of the page). You need to enter the following information:

Enter the Repository name and description, and select create. The repository link is displayed:

Assign a value to the link, go to Xcode, Source Control-> first item-> Configure..., and then select Remotes:

In Add Remote, enter Name (your project Name) and Address (previous link Address), then Source Control-> Push, select the newly created link, and Push ~

Now, refresh the GitHub homepage. Your project has been successfully added ~!

 

 

Related Article

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.