Swift explanation 20 -------- use git in xcode to manage source code and submit the code to github

Source: Internet
Author: User
Tags how to use git using git

Swift explanation 20 -------- use git in xcode to manage source code and submit the code to github
Use git in xcode to manage source code and submit the code to github

This article records how to use Git as the source code control tool in Xcode and how to integrate the local Git repository with the repository on remote Github, although this chapter has nothing to do with swift, but I still put it here. I think it is critical to learn swift.

1. Use git source code control in xcode

Currently, both versions of ELE. Me xcode 4 and later are integrated with the Source Control tool. Therefore, it is very convenient to use git to manage new projects.

We only need to check the checkbox when creating a project.

Xcode is automatically created for us and git source code management. The. git folder should be in our project directory. If not. You can view hidden files. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: java;"> defaults write com.apple.finder AppleShowAllFiles TRUE

At this time, we can have a lot of operations on Source Control.

If you want to add git to a previous project, first go to the project directory

cd /Users/YOUR-USERNAME/Desktop/NoGitExample 

Then

git init

This will Initialize an empty source. If you view it in the Finder or enter the ls command, you will see that the. git subdirectory has been created, which is good. Then enter:

git add . 

In this way, all contents in the current directory are added to the source. Finally, enter the following command:

git commit -m 'Initial commit’ 

In this way, add git to the project. For detailed git operations, refer to using Git for source code control in Xcode.
Very detailed, very good. The first part is the clip in it.

2. How to Integrate Xcode's local Git repository with Github's remote Repository

Github's philosophy stems from Git, which is not completely the same. But in terms of version control, there is little difference. Therefore, you can use Xcode's built-in Git management function to connect to Github without installing the Github client.

We can use SSH connection and asymmetric public key authentication. Link xcode with github. Of course it should be okay if it is not connected. However, it is difficult to enter the user name and password each time.

ssh-keygen -t dsa -f ~/.ssh/id_dsa

You will be prompted to enter the password. Twice

Your identification has been saved in /Users/xx/.ssh/id_dsa.Your public key has been saved in /Users/xx/.ssh/id_dsa.pub.

Then, you will be prompted for these two sentences. Go to the/Users/xx/. ssh/id_dsa.pub file and find a long string of public key letters.

You can also use this command to view the cat ~ /. Ssh/id_dsa.pub

Log on to the git official website and click your avatar --> Settings-> SSH keys-> add Key

Then write a title randomly and copy the long string of letters to the key.

Then, test. ssh dz $ ssh-T git@github.com in the console
If

 Hi xxxxx! You've successfully authenticated, but GitHub does not provide shell access.

Prove successful!

This error Permission denied (publickey) may occur)
Try this method.

You only need to modify the/etc/ssh/sshd-config file and change PermitRootLogin no to yes, PubkeyAuthentication yes to no, and AuthorizedKeysFile. add # block before ssh/authorized_keys, and change PasswordAuthentication no to yes.

This is an online method. The/etc/sshd-config file is of this structure. No ssh level

Then add a remote address for the local project.

Go to the following interface

Write the Name according to your preferences. Write the github repositorie Address.


Just copy it here.
Then push. Don't say you can't find push !! Source Control Sub-menu

An error may be reported here (xcode 6)

Could not read from remote repository.Please make sure you have the 。。。。。。。。

If it is xcode 7, it may report

The local repository is out of date.Make sure all changes have been pulled from the remote repository and try again.

Don't worry, it's because readme. md is not created locally in the new github project. You need to pull it down.

On the terminal, first enter your project directory, cd ......
The git pull command is used to retrieve updates from a branch of the remote host and merge the updates with the specified local branch.

Git pull <Remote Host Name> <remote branch name>: <local branch name>

It is now in the current directory of the project.

git pull --rebase xxx master

Xxx is the Name of Add Remote. master is the Name of your branch. The default value is master.

I have encountered so many problems, if you have encountered other strange problems. ..

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.