Git rookie entry-level tutorial

Git is a distributed version control system that helps developers manage and track code changes. The following is a nanny-level Git tutorial, including overview, theory, instructions, complete steps for creation and code initialization, branches and conflicts , and problems encountered.

overview



Git is an open source distributed version control system originally developed by Linus Torvalds. It can track code changes, record the modification of each commit, and easily roll back to the previous version. Git also supports multi-person collaborative development, which can easily merge the codes of different developers.

theory



The core concept of Git is a repository , which is a place to store code. Each repository has a master branch (master) where stable code is stored. Developers can create a new branch (branch), develop on the new branch, and then merge the changes into the main branch.

instruction



Git has many commonly used instructions, the following are some commonly used instructions and their functions:

- git init: Initialize a new Git repository.
- git add: Add files to the temporary storage area.
- git commit: Submit the changes in the temporary storage area to the warehouse.
- git clone: ​​Clone a remote warehouse to the local.
- git push: Push the modification of the local warehouse to the remote warehouse.
- git pull: Pull the latest changes from the remote repository.
- git branch: view, create and delete branches.
- git merge: Merge changes from one branch into another.

Complete steps of creation and code initialization



1. Create a new folder locally as the root directory of the Git repository.
2. Open the command line tool and enter the folder.
3. Initialize a new Git repository with the command git init.
4. Use the command git add to add the files to be tracked to the temporary storage area.
5. Use the command git commit to submit the changes in the temporary storage area to the warehouse.

Branches and Conflicts



1. Use the command git branch to view the current branch list.
2. Create a new branch with the command git branch <branch-name>.
3. Use the command git checkout <branch-name> to switch to the specified branch.
4. Develop on a different branch.
5. When there is a conflict between the two branches, use the command git merge to resolve the conflict.

problems encountered



In the process of using Git, you may encounter some problems. Here are some common problems and their solutions:

1. Encountered error prompts when submitting: You can use the git status command to view the current status, and perform corresponding operations according to the prompts.
2. Conflicts encountered when merging branches: You can use the git diff command to view the specific content of the conflict and resolve the conflict manually.
3. An error message is encountered when deleting a branch: you can use git branch -D <branch-name> to forcibly delete the branch.

The above is a nanny-level Git tutorial, I hope it will be helpful to you!

Guess you like

Origin blog.csdn.net/qq_50942093/article/details/131456428