1. Initialization

Use Git on Windows, download it from the official website, and install it with the default options.

Linux provides git functions and can be used directly on terminals. If it is not installed, use the system software package installation instructions to install it.

After installing Git, you can set your own user name and mailbox on your computer.

#-- create a single repository name
git config --global user.name "XXX"
git config --global user.email "[email protected]"

Reset username and mailbox
git config --global --replace-all user.name "XXX"
git config --global --replace-all user.email "[email protected]"

# Remove global Settings
git config --unset --global user.email
git config --unset --global user.name

# View the configuration details
git config -l
Copy the code

Two, common operations

Initialize the repository
git init

Check the current status of the warehouse
git status

# Check the file changes
git diff A.py B.py

# Add all files in the project with one click
git add *

Submit all the documents in the backlog area and note the information
git commit -m "Added a file" 
Copy the code

Version control

The submission record includes the submitter, submission remarks, version number (sha1 generated).
The pretty parameter is added to simplify the display, where HEAD represents the current version
git log(--pretty=oneline)

# View detailed submission information
git show 89adf98ads9134oj

Reset the file forward X versions, fill in as needed
git reset --hard HEAD~X
# Jump to this versionGit reset --hardCopy the code

Use the above git log command to check the version number. If you have jumped to an earlier version and closed the terminal window, you cannot find the latest version number using the Git log command.

Output each command change, can find the latest version number. Realize the backward jump.
git reflog
Copy the code

Four, disassembly branch

Create branch dev
git branch dev
# Jump to branch dev
git checkout dev/git switch dev

Create and switch to branch dev
git checkout -b dev/git switch -c dev
The asterisk is the current branch
git branch
Copy the code

When the branch code is complete, merge it into the main line.

# Apply the dev branch to the original master thread
git merge dev
After a successful merge, the branch can be deleted
git branch -d dev
Copy the code

If you need to use the branch function, you should keep the master main line still, each member in the branch to create and modify, and merge the code in the dev branch, after the test is correct, the summary into the master main line.

Five, remarks label

# View all tags
git tag
# View the details of the hashtagGit show v1.0Add a tag to the current version locationGit tag v1.0# tag the specified versionGit tag v0.9 f52c633Add tag, comment, specify idGit tag -a v1.0 -m "add tag" f52C633Copy the code

In all current operations, labels are stored locally.

Push all local tags to the remote repository
git push origin --tags
Push the specified tag to the remote repositoryGit push origin v1.0Copy the code
Delete local tagsGit tag - d v1.0Delete the remote tagGit push origin: refs/tags/v1.0Copy the code

6. Remote warehouse

1. The key

To synchronize the connection between the local repository and the server repository and send and receive file versions, add the local SSH Key to the whitelist of the server. If the host is not whitelisted, the code obtained from the server repository is read-only and cannot be modified. The key is not required; if HTTP push and pull code is used, only the account password is required.

# generate key
ssh-keygen -t rsa -C "[email protected]"
Copy the code

SSH folder, which contains the id_rsa.pub file. The public key in this file is used to create SSH keys. The SSH folder location can be customized as prompted.

2. The warehouse

If you need to create a private repository, for example, create a repository at/SRV /GitStore/ icode.git.

cd /srv/GitStore
git init --bare iCode.git
Copy the code
Connect to the server repositoryGit remote add origin [email protected]: / SRV/GitStore/iCode. GitGet code from the server repository
git pull origin master
Upload local code to the repository
git push origin master

# Clone pull (out of folder)
git clone[email protected]: / SRV/GitStore/iCode. GitCopy the code