Summary of the git

Git is a distributed version control system.

How Git works

Git and the code hosting center

A code hosting center is a web server-based remote code repository, commonly referred to simply as a remote repository.

  • Local area network (LAN)
    • GitLab
  • The Internet
    • GitHub (Internet)
    • Gitee Code Cloud (Domestic website)

Git installed

It-scm.com/

Git –version

Select the Git installation location, a non-Chinese directory with no Spaces, and then proceed.

Git options are configured, default Settings are recommended, and then next.

Git installation directory name, do not change, directly click Next.

Git’s default editor. It is recommended to use the default Vim editor and click Next.

The default branch name is set to let Git decide. The default branch name is master

Change the Git environment variable, select the first one, do not change the environment variable, only use Git in Git Bash.

Select the background client connection protocol, the default OpenSSL, and then the next step.

Configure the Git file’s end-of-line newline character, use CRLF for Windows and LF for Linux, select the first automatic conversion, and proceed to the next step.

Select the Git terminal type, the default Git Bash terminal, and proceed to the next step.

Select the Git pull merge mode, default, and next.

Select Git’s credential manager, the default cross-platform credential manager, and next.

For other configurations, select default Settings and then next.

Lab functions, technology is not mature, there are known bugs, do not check, then click the Install button in the lower right corner, start installing Git.

Click Finsh button to install Git successfully!

Git git

Name of the command role
Git config –global user.name Git config –global user.name Setting a User Signature
Git config –global user.email Setting a User Signature
git init Initialize the local library
git status View local library status
Git add file name Add to staging area
Git commit -m “Log info” file name Commit to a local library
git reflog Viewing Historical Records
Git reset — Hard version number Version of the shuttle
git config –global credential.helper store Enter the user name and password again to remember

1. Set the user signature

  1. The basic grammar

    git config --globalUser. name Git config --globalUser. Email mailboxCopy the code
  2. In field case

Description:

The signature is used to distinguish between operator identities. The user’s signature information can be seen in the submission information of each version to confirm who committed the submission. The first git installation will not commit code unless you set up a user signature.

Note: Setting a user signature here has nothing to do with the account you will log into GitHub (or any other code hosting center) in the future.

2. Initialize the local library

  1. The basic grammar

    git init

  2. A case in field

  3. The results view

    The.git folder appears under the folder

3. Check the status of the local library

  1. The basic grammar

    git status

  2. A case in field

    • First view (Workspace does not have any files)

    • New file (hello.txt)

    • View again (untraced file detected)

4. Add a staging area

4.1 Add files from the workspace to the staging area
  1. The basic grammar

    Git add file name

  2. A case in field

5. Commit the local library

5.1 Commit the files in the staging area to the local library
  1. The basic grammar

    Git commit -m “Log info” file name

  2. A case in field

6. Modify the file (hello.txt)

vim hello.txt
Copy the code
6.1 Viewing the Status (Files are modified in the Workspace)
git status
Copy the code
6.2 Add the modified file to the temporary storage area again
git add hello.txt
Copy the code
6.3 Viewing status (Workspace changes added to staging area)
git status
Copy the code

7. Historical version

7.1 Viewing Historical Versions
  1. The basic grammar

    Git reflog Check the version information

    Git log Displays the version details

  2. A case in field

7.2 Version Shuttle
  1. The basic grammar

    Git reset — Hard version number

  2. A case in field

Git switch version, the bottom actually moves the HEAD pointer, the detailed principle is shown below.

8. git SSL certificate problem: unable to get local issuer certificate

This problem is due to no trusted server HTTPS authentication being configured. By default, cURL is set to distrust any CAs, that is, it does not trust any server validation.

Run the following command:

git config --global http.sslVerify false
Copy the code

9. Remember the user name and password

git config --global credential.helper store
Copy the code

Enter the user name and password again

10. View branches

Git branch -r git branch -a git branch <branchname> // Create a new git branch Branch -d <branchname> git branch -d -r <branchname> Git branch -m < oldBranch > <newbranch> // Rename local branch /** * rename remote branch: * 1. -d --delete: delete -d --delete --force -f --force: force -m --move: -m --move --force Shortcut keys -r --remote: remote -a --all: allCopy the code

Git fetch

Git fetch < remote host name > // This command will fetch all updates from a remote host locallyCopy the code

If you only want to fetch updates for a particular branch, you can specify the branch name:

Git fetch < remote host name >Copy the code

The most common command is fetching the master branch of the Origin host

git fetch origin master
Copy the code

When the update is fetched, a FETCH_HEAD is returned, which refers to the latest status of a branch on the server and can be used locally to view the updated information:

git log -p FETCH_HEAD
Copy the code

12. Git pull

The process of git pull is as follows:

git fetch origin master		// Pull the latest content from the master branch of the remote host
git merge FETCH_HEAD		// Merge the latest pulled content into the current branch
Copy the code

To fetch an update from a branch of a remote host and merge it with a locally specified branch, the complete format can be expressed as:

Git pull < remote host name > < remote branch name >Copy the code

If the remote branch is merged with the current branch, the part after the colon can be omitted:

git pull origin next
Copy the code

13. Create a local branch

Git Checkout branch name switches to the local branch

Git checkout -b branch name creates the local branch and switches

Git push Origin local branch name

14. Delete the remote branch

git push --delete origin dev

Run git branch -d dev to delete a local branch