The basic commands of git use

Basic usage of git

1. Installation of git

The official website link address https://git-scm.com/downloads
Click to download the next step, it is ok, after successful installation, in the window environment, right-click the mouse to appear Git Gui and Git Bash, Gui is a graphical interface, Bash is a linux command-line interface . Just use bash.

2. The local basic commands of git

git clone downloads code or text information from a remote repository to the local.

git clone xxx (https address)

git init creates a local repository on this machine and initializes it. The .git file appears and cannot be edited.

git add . or git add (a.html) to an html file and add it to the code staging area.

git commit -m "xxxx" -m represents message information, and "xxx" is the log note of the modified code.
commit will submit the code information to the local repository.

git status View the modification information

3. git submit and pull remote warehouse command

git push push to remote repository

-The first usage: git push https://xxxxxx master ; master is the main branch name.

-The second usage: git remote add origin https://xxxxxl ; git remote aliases the remote repository origin can be any name.

git push origin master is directly submitted to the remote code repository. Only after the local operation is completed, the modified part can be uploaded to the remote repository.

git pull origin master pulls updated information from the remote repository.

git remote -v View alias information.

4. Git establishes a branch for multi-person collaboration

git branch View the current number of branches.

git branch aaa creates a branch, that is, backs up an identical content from the trunk, but unlike the rough copy of svn, git branching is just to create a snapshot of the main branch.

git checkout aaa Switch to branch aaa, you can modify the content of aaa to modify the code information without affecting the content of the main branch

git merge aaa Switch to the main branch to merge branches, and merge the code modified by aaa into the main branch to complete multi-person collaboration.

5. Log viewing and version switching

git log View all modified logs, the front line is too long is not conducive to viewing.

git log --pretty=oneline to see in one line.

git reflog View all version change log records

git reset --hard HEAD^^^^ Rollback version A ^ represents a record.

git reset --hard xxxxx The first few digits can be abbreviated by the hash value rollback (xxx) of each record.

hash value

6. Configure the public key to facilitate submission to the remote warehouse

- Remote warehouse address in configuration format git remote add remote warehouse name remote warehouse address

-Create ssh key ssh-keygen -t rsa -C "email address"

-Put the public key on the server
Open id_rsa.pub with Notepad and copy it to the ssh key to create a new ssh key.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325275446&siteId=291194637