This article has participated in the third “topic writing” track of the Denver Creators Training Camp. For details, check out: Digg Project | Creators Training Camp third is ongoing, “write” to make a personal impact.

Introduction of Git

Git is a distributed version control system, it can not be restricted by the network connection, plus many other advantages, has become the program developers do project version management of the first choice, non-developers can also use Git to do their own document version management tool.

Git has a lot of APIS, but in fact, 90% of the requirements of the project only need to use a few basic functions, so this article will talk about how to use Git in the project from two aspects of pragmatism and in-depth exploration. Generally speaking, after reading the section of pragmatism, you can start to use Git in the project.

Preparation stage

Go to the Git official website to download the installation package suitable for you. After installing Git, open the command line tool, go to the working folder, and create a new demo folder.

Go to Github and sign in to create a repository.

Common operations

  • The so-called pragmatism is to master the following knowledge can play Git, easy to cope with more than 90% of the requirements. Here is a list of pragmatic Git commands to look at first

  • git clone

    • Pull code from git server
git clone https://github.com/encorehe
Copy the code
  • git config
    • Configure the developer username and email address
    git config user.name **
    git config user.email **@qq.com
Copy the code
  • git branch

    • Create, rename, view, and delete project branches. When developing a project with Git, it is generally done in the development branch and merged into the trunk after development.

    Git branch daily / 0.0.0

    • Create a daily development branch called Daily /0.0.0, as long as the branch name does not include special characters.

      Git branch -m daily/0.0.0 daily/0.0.1

      • If the previous branch name is not appropriate, you can rename the new branch to daily/0.0.1

      git branch

      • You can run the branch command without parameters to view the branch list of the current project

      Git branch - d daily / 0.0.1

      • If the branch has completed its mission, you can use the -d parameter to delete the branch. To continue with the next step, do not delete the branch
  • git checkout

    • Switch branch
      • Git checkout daily / 0.0.1
        • Switch to the Daily /0.0.1 branch where the rest of the action will take place
  • git status

    • View the file change status
    • git status
  • git add

    • Add file changes to staging area
    • git add README.md
      • You can add the file to the staging area by specifying the file name readme. md. Git add. Git status Changes to be committed:
      On branch daily/0.01.
      Changes to be committed:
        (use "git reset HEAD <file>..." to unstage)
          modified:   README.md
      Copy the code
  • git commit

    • Commit file changes to the repository

    Git commit -m

    • The -m parameter is used to enter the submission description text directly on the command line
  • git push

    • Push local code changes to the server

    Git push origin daily / 0.0.1

    • Now go back to the Github project home page and click the Branch: Master drop-down to see the daily/00.1 Branch you just pushed
  • git pull

    • Pull the latest code from the server to local

    The git pull origin daily / 0.0.1

    • If other project members make changes to the project and push them to the server, we need to update the latest changes locally. Let’s simulate this situation here.
    • Go to the Github homepage of the project, then go to the Daily /0.0.1 branch, make some changes to the readme. md file online and save it, then execute the command above, it will pull the changes to the local, use the editor to open readme. md. You will notice that the file has been synchronized with the content online.
    • If the online code changes, and there is change for your local code, pull the code may conflict with your local changes, usually a Git merge automatically deal with the conflict, but if the change is the same line, then need to merge the code manually, edit the file, save the latest changes, again through the Git add. And git commit -m ‘XXX’ to commit merge.
  • git log

    • View version submission records
  • git tag

    • Mark milestones for the project