Technology Sharing

GIT basic concepts and simple usage

2024-07-11

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Git is a distributed version control system that tracks changes to files and records those changes, enabling team members to collaboratively edit and manage code.

The basic concepts of Git include the following aspects:

  1. Repository: In Git, a repository is a place where code and historical versions are stored. There can be local repositories and remote repositories.

  2. Branch: A branch is a copy of the code created based on the main branch (usually master). By creating and switching branches, you can develop and modify the code without affecting the main branch. This makes it easy to develop multiple tasks or multiple features at the same time.

  3. Commit: Commit is the process of saving the modified code to the Git repository. Each commit generates a unique commit ID that records the code changes and author information.

  4. Merge: Merge is the process of merging the code of two or more branches together. When the development work of a branch is completed, it can be merged into the main branch or other branches.

  5. Remote: Remote refers to a Git repository located on the Internet. It can be a repository on a server shared by team members, or a repository on a code hosting platform (such as GitHub, Bitbucket, etc.).

The use of Git includes the following steps:

  1. Initialize the warehouse: Use the commandgit initTo initialize the current directory as a Git repository.

  2. Add files: Use commandgit addAdd the files you want to track to the staging area.

  3. Submit files: Use commandgit commitSubmit the files in the staging area to the warehouse.

  4. Creating and switching branches: Use commandsgit branchTo create a branch, use the commandgit checkoutSwitch branches.

  5. Merge branches: Use commandgit mergeMerge code from one branch into another.

  6. Remote Operation: Using Commandsgit remoteTo manage remote repositories, use commandsgit pushPush the code from the local repository to the remote repository.

  7. Version rollback: Use commandgit checkoutorgit resetto roll back to a specific version.

The above are the basic concepts and usage of Git, which can help team members better collaborate on development and manage code.