Getting Started with Git and GitHub

A, GitHub

GitHub provides developers Git repository hosting service can be code-sharing, team collaboration, created the concept of socialization (social coding) programming.

Second, the difference between Git and GitHub

Developer source code into "Git" repository, Git and GitHub provides warehousing services on the network.

Three differences, Git and SVN's

  1. The same point:
    are version management, namely management history of updates, such as adding or changing the source code recording process, and roll back to a specific stage, and so can recover accidentally deleted file version management, namely management history of updates, e.g. add or change the source code of the recording process, roll back to a particular stage, recover accidentally deleted files

  2. difference:

  • Git is a centralized version control, only the central server has a code, Git is a distributed version control, on everyone's computers have a complete code.
  • Centralized version control safety issues, when the central server linked to everyone no way to work.
  • Centralized version control needs networking to work, if the speed is too slow, then the document will be submitted to a slow impossible for anyone to endure. The distributed version control does not require networking can work.
  • New distributed version control branch, merge branching operation speed is very fast, and centralized control of the new version copy corresponding to a branch of the complete code.

Four, GitHub's special services

  1. Pull Request
    Developer after local modifications to the source code (such as repair Bug, adding new features) can be requested by the owner of the warehouse Pull Request allows modifications incorporated into the Git repository. After local developers to modify the source code (such as repair Bug, adding new features) can be requested by the owner of the warehouse Pull Request allows modifications incorporated into the Git repository.

  2. Issue
    will be assigned to a task or a problem Issue tracking, management, communication,

  3. GitHub Flavored Markdown
    on GitHub, all places (such as Issue, comments, Wiki) design input text can use Markdown syntax

  4. News Feed
    will be added to the Watch warehouse interested, you can update the information in time to see the warehouse News Feed

  5. Wiki
    , anyone can make changes to an article by Wiki, commonly used in the preparation of development documentation or manuals


Here we explain through an example, is divided into three parts:

  • Create a repository on Github
  • And create a new Xcode project locally
  • To submit to the new Xcode project repository on Github

Sixth, create a Git repository on Github

  1. Browser open https://github.com, click Sign up to register, if already registered then click Sign in to log in, can not say here in detail the registration process.
  2. Click New, start a new Git repository
  3. Enter the Git repository initialization information:
    Repository name : the name of the warehouse, I generally use the project name directly
    the Description (optional) : Description Warehouse (optional)
    Public / Private : whether public, Private is private fee-based services, general open source project selection Public ( If you want to use free private Git, Git can choose the service provided by the cloud code: http://git.oschina.net )
    the initialize Repository with the this README a : If on the hook, GitHub will automatically initialize the warehouse and set the README file (displayed in the warehouse the contents of the home page, usually containing project summary, use, license, etc.), allowing users to instantly clone this repository. If you want to add an existing Git repository Github, it is recommended not checked. We are here not checked.
    .Gitignore the Add : drop-down selection, .gitignore file can be automatically generated at initialization, gitignore file version management is not required to record in a Git repository file. Drop-down menu contains the main language and framework, you can choose in the future to be used. Not choose us.
    A License the Add : drop-down menu to select a license file to be added. If the code repository contains already identified the license agreement, you can choose. Here we do not choose.
  4. Click Create Repository complete warehouse creation.

Seven, create Xcode project

Xcode When you create a project, directly check Create Git repository on my Mac, that is, create a git repository in a local project
Create a project

Six, Git command

  1. git init (initialize warehouse)
    If you create a project on a step, did not choose to create a git repository, you need to think through the command to initialize git repository
git init 
  1. git Status (See warehouse status)
    Red Untracked rear part of the file is not added to the files in the file control git.
git status

Here Insert Picture Description

  1. git add
    via "git add + filename", can be added to the Git repository specified file temporary storage area, "git add." said it would join all the files in the directory under Git repository staging area.
git add .

Here Insert Picture Description

  1. git commit -m ''
    will present in the cache files are actually saved to the history warehouse. With these records, we can restore the files in your working tree. behind m '' as the text message submission, an overview of the submission.
git commit -m 'First commit'
  1. git remote add add a remote repository

Associate local repository to Github remote repository created in Step 6, as Github copy the address of the remote repository, execute git remote add <project name> <Remote Address>
Here Insert Picture Description

git remote  add origin https://github.com/dolacmeng/demo.git
  1. git push to push to a remote repository
    execute git push command to the current local content pushed to the remote repository origin master branch, the first time you push, add -u origin master said it would set up a warehouse of origin master branch upstream of the current branch to a local warehouse (upstream)
git push -u origin master

At this point in turn requires us to enter GitHub username and password, press enter to wait for the upload is complete, then we can see on the github repository file has been submitted to us:
Here Insert Picture Description

  1. git clone from a remote repository clones
    We have already put on GitHub new warehouse is set to a remote repository, and to push the local code for this repository. Now we can put in a new computer program intact cloned locally, so that we can allow new developers with a collaborative development project.
git clone https://github.com/dolacmeng/demo.git
  1. git pull pull the latest remote repository branch
    to pull the latest code on Github repository through git pull command, synchronization code to other developers submitted.
Published 103 original articles · won praise 55 · views 380 000 +

Guess you like

Origin blog.csdn.net/dolacmeng/article/details/88224459