The use of iOS learning git

Source: Internet
Author: User

SVN is a centralized version control system, the repository is centrally placed in the central server, and work, with their own computers, so the first to get from the central server where the latest version, and then work, after the completion of the job, you need to put the work done to the central server. Centralized version control system must be networked to work, if the LAN can also, the bandwidth is large enough, fast enough, if under the Internet, if the speed is slow, I wonder.

Git is a distributed version control system, then it does not have a central server, everyone's computer is a full version of the library, so that the work of the time will not need to network, because the version is on their own computer. Since everyone's computer has a full repository, how do people collaborate? For example, they changed the file a on the computer, the other people also on the computer changed the file a, at this time, you two only need to put their changes to each other, you can see each other's changes.

    • The biggest feature of git compared to SVN,CVS is the provision of distributed code management.
    • Only one copy of the branch code! Log is local! Merging code is more convenient! More secure! The catalogue is more concise!

Basic command;
Sudo-s Get Absolute User rights
cd XXX Enter the XXX directory
LS (-a/-a) displays all files under the current path (hidden)
PWD Displays the current absolute path
mkdir xxx Create folder xxx
man xxx view XXX command manual

Then introduce the meaning of the git basic command;
Clone cloning remote Repository
Init Initialize Warehouse
Remote connection
Pull fetch new data from remote repository dropdown
Push uploads new or modified files from the local repository to the remote repository
Add files or modify files, commit and push before using
Log information submitted by the current warehouse
Status Current warehouse version state
Commit commits to the current warehouse
Branch Branch command, related additions and deletions check operation
Checkout use the last version of the remote repository to completely overwrite the current warehouse content/Select Branch Branch
Diff vs. Version content
Merge merged version content

Git Installation

    1. Install homebrew, and then install git via homebrew

Terminal input RUBY-E "$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install)"

    1. Installing Git via homebrew

Terminal Input $ brew install git

Access and use of public key

    1. Generate Public key:

Terminal Input $ ssh-keygen

    • The middle will let you enter the build directory, point to enter the default on the line.
    • Will let you enter your own key, input to remember will be used later (preferably with the boot password, or will forget)

    1. Get the public key:
    1. CD first to the directory where the public key is stored

Terminal Input $ ~/.ssh

    1. Get public key

Terminal Input $ cat ~/.ssh/id_rsa.pub

Use of public keys on GitHub:

    1. Go to account Settings, select ssh keys,add ssh key,title on the left, and paste the Key in the id_rsa.pub generated on your computer.
    2. Verify success:

Terminal input $ ssh-t [email protected]

If this is the first time it will prompt whether Continue , enter Yes you will see: You ' ve successfully authenticated, and GitHub does not provide shell access . This means that you have successfully connected to GitHub.

Git usage (based on Collectionviewsample engineering demonstration)

    1. Locate the file location you want (that is, the directory where you have the project)

Terminal input $ CD/USER/MAC/DESKTOP/OBJC copy/collectionsample

    1. Use the GIT init command to turn this directory into a repository that can be managed with git

Terminal input $ git init

Run:

2. Add the required projects to Git

Terminal input $ git add xxxx

(There are two things in my folder, so I added two times)

3. Submit the file to the repository with the command git commit

Terminal input $ git commit-m "wrote a collectionviewsample file"

5. Set up username and email because GitHub will record them every time a commit

Terminal input $ git config--global user.name "your name"
$ git config--global user.email [email protected]

The first thing to do when you install Git is to set your user name and e-mail address. This is important because each git commit uses that information. It's been embedded in your submission forever.

6. If you don't want to enter a password each time you connect to the remote repository, enter the following command
Terminal input $ git credential-osxkeychain

7. Create a project on GitHub

Login GitHub , and then, in the upper-right corner, locate "Create A new repo" button to create a new warehouse.
in the Repository name fill in, other keep the default settings, click "Create Repository" button, you have successfully created a new Git Warehouse

8. Connect to GitHub locally

Terminal input $ git remote add origin [email protected] (GitHub account name/repository Name.git

9. Push the local repository to the remote repository

Terminal input $ Git push-u Origin Master

Upload to this new project is complete.

Common git errors

1. If you enter git remote add origin [email protected]:github account name]/gitdemo (project name). Git

Tip error Message: Fatal:remote origin already exists.

The solution is as follows:

1. First enter GIT remote RM origin

2. Then enter git remote add origin [email protected]:github account name]/gitdemo (project name). Git

You won't get an error!

2. If you enter $ ssh-t [email protected]
Error message: Permission denied (PublicKey). Because the newly generated key cannot join SSH, it will cause the connection to not be on GitHub.

The solution is as follows:

    1. Enter $ ssh-agent First, and then enter $ Ssh-add ~/.ssh/id_key, so you can.

3. If you enter a GIT push origin master

    1. Tip error message: error:failed to push som refs to ....

The solution is as follows:

1. First enter the GIT pull Origin master//start the remote server github file down

2. Then enter $ GIT push origin master

    1. If an error occurs FATAL:COULDN ' t find remote ref Master or fatal: ' Origin ' does not appear to be a git repository and fatal:could not re Ad from remote repository.

You need to re-enter Git remote add origin

The use of iOS learning git

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.