Git installation and basic use of interaction with the server

Git installation

Install Git on Windows


Wamp has been installed on windows, the specific environment is: Apache / 2.4.39 (Win64) + PHP / 7.2.18 + MySQL5.7.26

  • Git download address: https://gitforwindows.org/
  • Double-click the downloaded Git-2.22.0-64-bit.exe file and click "Next>":
    Git installation license information, click "Next>"
  • Configure the download path.
    Insert picture description here
  • Select the component you want to download, the default check is as follows:
    Insert picture description here
  • Configure shortcut keys:
    Insert picture description here
  • Configure the default editor, select the default (vim):
    Insert picture description here
  • To configure how to use Git, select the default second one (you can use the command line or a third party. Third-party refers to software that can graphically Git, eg: TortoiseGit)
    Insert picture description here
  • Configure the SSL / TLS library and select the first one by default (use OpenSSL):
    Insert picture description here
  • Configure Git's way to wrap files, choose the first one by default (change the Windows mode to Unix mode):
    Insert picture description here
  • Configure the terminal emulator using Git Bash, select the default first (MSYS2):
    Insert picture description here
  • Configure some other options, the first and second are selected by default (file system cache & certificate manager):
    Insert picture description here
  • Configure add options, not selected by default. Click Install to install
    Insert picture description here
  • After the installation is complete, open git-bash.exe to start using it.
    Insert picture description here

Git use

User Info

// Configure personal user name and email address:
$ git config --global user.name “cry”
$ git config --global user.email [email protected]
// View configuration information
$ git config --list
/ / You can also directly check the setting of an environment variable, such as the name
$ git config user.name

Insert picture description here

Key

// Generate SSH key process
$ ssh-keygen -t rsa -C '[email protected]'
// Enter the path where you are and check the key
$ cd ~ / .ssh
$ ls // If you want to log in to the remote server's git , You need to add the contents of id_rsa.pub to the server
id_rsa (private key) id_rsa.pub (public key)

clone

// Clone the project of the remote server. Since the first connection, you need to enter yes to establish the connection. You will find that the known_hosts file is generated under .ssh to store the server address just connected, and the file under clone is stored in the folder cry.
$ git clone [email protected] : /usr/local/cry/.git

Insert picture description here

Create a branch and push your project to the server

// Create and switch to the "chen" branch
$ git checkout -b chen
// View the branch under the current directory
$ git branch
// Push the local branch to the remote server
$ git push origin chen

// Create a new file
$ mkdir test
$ vim test / test.php
$ git status -s // The git status command is used to view the current status of the project
?? test /

// The git add command can add the file to the cache
$ git add.
$ git status -s
A test / test.php
// Execute git commit to add the contents of the cache area to the warehouse
$ git commit -m “chen-branch test /test.php "

//在本地将chen分支合并到master上
$ git checkout master
Switched to branch ‘master’
Your branch is up to date with ‘origin/master’.
$ git merge chen
Updating a4860ac…7b30e8d
Fast-forward
test/test.php | 3 +++
1 file changed, 3 insertions(+)
create mode 100644 test/test.php

//将本地分支master推到远端分支cry上
$ git push origin master:cry
Enumerating objects: 14, done.
Counting objects: 100% (14/14), done.
Delta compression using up to 4 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (13/13), 1.02 KiB | 104.00 KiB/s, done.
Total 13 (delta 3), reused 0 (delta 0)
To 211.71.149.244:/usr/local/jwh/.git
a4860ac…7b30e8d master -> cry

// Finally merge the cry branch on the server to the master

Published 9 original articles · praised 1 · visits 851

Guess you like

Origin blog.csdn.net/weixin_36466834/article/details/95246855