I. Remote Operation
1.1 Distributed Version Control System
A distributed version control system, simply put, is a central server repository connected to multiple local server repositories. This allows multiple developers to view their respective code.
1.2 Cloning a remote repository
git clone [ Repository URL ]
Using HTTPS protocol: There are no requirements when using HTTPS, and you can directly clone it.
git clone [ Repository URL ]
Using the SSH protocol: Step 1: Create an SSH key. In your user directory, check if there is a `.ssh` directory. If so, check if there are
`id_rsa` and `id_rsa.pub` files in this directory. If they already exist, skip to the next step. If not, you need to create an SSH key:
ssh-keygen -t rsa -C "your email"
Locate the `.ssh` directory in your user directory. There you will find two files: `id_rsa` and `id_rsa.pub`. These are the SSH key pair. Copy the contents of `id_rsa.pub` into your public key configuration.
1.3 Pushing to remote warehouses
git push <remote host> <local branch>:<remote branch>
1.4 Pulling a remote repository
git pull <remote host> <remote branch>:<local branch>
1.5 Ignore special files
In daily development, there are some files we don’t want or shouldn’t commit to the remote repository, such as configuration files containing database passwords. How do we let Git know this? Create a special `.gitignore` file in the root directory of your Git workspace, and then enter the names of the files you want to ignore. Git will then automatically ignore these files.
# My configurations:
*.ini
*.so
For example, if we want to ignore all files ending with .so and .ini, the content of .gitignore would be as follows:
When we want to commit a file that is configured to be ignored, we git add -f [file name] can also select files to not exclude in the .gitignore file by adding an exclamation mark before the filename.
When we write too many configurations, we can git check-ignore -v [file name] check whether newly created files or workspace files are ignored and the reason for the ignore.
Configure command aliases: Simplify `git status` to `git st`, the corresponding command is:
git config --global alias.st status `--global`
to apply globally.
II. Tag Management
A tag can be simply understood as an identifier for a particular commit, essentially an alias. For example, when a project releases a version, a tag like “v1.0” is used to mark the milestone of the last commit.
The command git tag [tag name] : can be used to tag the most recent commit.
The command git tag [tag name] [commit_id] : tags the commit corresponding to this commit ID.
git tag -a [name] -m "XXX" [commit_id] : Git also provides the ability to create tags with descriptions; use -a to specify the tag name and -m to specify the description text.
git show [tag name] : View tag details:
git tag -d [tag name] : Delete tag
git push origin <tag name> : Push tags to remote repository
git push origin --tags : Push all local tags to the remote repository
If the tag has already been pushed to the remote repository, deleting it remotely is a bit more complicated.
First, delete it locally
git tag -d [ tag name ]
then delete it remotely.
The delete command is also `push`, but the format is as follows:
git push origin :[ tag name ]