This week, the group shared the knowledge of Git instruction, which is very useful for every new developer. I don’t advocate rote memorization of too many Git instructions at once. After all, Git is just a tool.

1. What is Git?

Git is an open source distributed version control system.

Version control: In layman’s terms, Git manages development documentation, backing it up every time it is committed. It allows developers to view, roll back, compare historical commits, and more.

Centralized: Centralized means that development documents are backed up on one server and not stored on the local computer.

Distributed backup: Data is backed up on multiple servers and can be synchronized among servers to avoid serious consequences caused by the failure of one server. Git takes a distributed approach.

As shown below: Remote server, local PC have backup files. Interaction and synchronization via Git instructions.

2. How does Git work?

Git is divided into three areas on the local computer: workspace, staging, and repository, which represent the three states of local files.

A normal workflow (as shown below) : write code in the current IDE (corresponding workspace), commit files to staging via Git Add, and commit files to the local repository via Git commit. Finally, commit to a remote repository via git push.

3. Branch management?

Git branches: Branches are created to subdivide the different development states of a project without interfering with each other. Git branches commonly used for a project are master,dev,feature, and hotfix.

Dev branch: Stores code under development, but not yet tested. Hotfix: All the above branches, except the master branch, will eventually be merged into the Master branch after passing the test.Copy the code

If you are not used to the Git bash interface, you are recommended to use the Sourcetree visual interface for foolproof git operations.

4. Common git commands?

A. Basic workflow: clone the remote repository and synchronize the modified files to the remote repository through git status,git add, Git commit and Git push commands.

    git clone-->git status-->git add-->git commit -m-->git push
Copy the code

B. Synchronize remote warehouse:

    git pull
Copy the code

C. Viewing records:

    git show   
    git log
Copy the code

C. Branch operation:

Git checkout -b branchname Git checkout -d branchname git merge/rebaseCopy the code

Git provides different undo commands according to the state of the workspace:

Git checkout -- git checkout -- git checkout -- git checkout -- but, A workspace to modify kept) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- gorgeous line -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the git revert commitId Git revert -- Abort when git revert conflicts occur Suspend the revert operation) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- gorgeous line -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the git reset commitId Git reset --hard commitId git reset --hard commitIdCopy the code

Tips: Git is very thoughtful, it will give you a hint of what to do next. Learn to read prompts to use Git commands flexibly. I will write another article about this.

5. Connect related knowledge points

If you have any questions, please leave a comment. For more git instructions, visit git-scm.com/docs.

Next time: where is Webpack?