Article directory
Foreword:
If you have not read the basic operations of git in the previous chapters, it is recommended to read it first and then look at this remote operation. This way you will have a deep understanding of git~~
Next we discuss the main topic of this chapter:
Git is a distributed version control system that allows teams to collaborate on development and track code changes. Remote operation is an important concept in Git, which enables developers to share and synchronize code between different computers. I won’t introduce much here. You can go to Baidu to find it by yourself~~
This tutorial uses code cloud ( gitee.com ) to demonstrate
Create a new remote warehouse clone
- The first thing you need to do is register an account of your own.
- Then create a new warehouse
-
There are two ways to clone the repository locally, one
https
isssh
-
We don’t use it
https
because https is relatively simple.- The first is to configure the user name and email address (the configuration command here is described in the initial git operation ) and then use this command directly
git clone 复制的仓库链接
- The first is to configure the user name and email address (the configuration command here is described in the initial git operation ) and then use this command directly
-
Next we will use this
ssh
to configure- Use ssh to clone the warehouse. Since we have not added the public key to the remote library, the cloning will fail. We will not demonstrate it here. Next, we will start configuring how to add the public key.
-
First open settings->ssh public key->public key
-
So where to get the public key here? Of course, it is on your own computer or remote server~~
- I demonstrated it here on my own computer, and the remote server obtains it in the same way~~
- Enter the command, note: change it to your own email address~~
ssh-keygen -t ed25519 -C "[email protected]"
- Then the address will be displayed at the address in the picture above. Just find this folder. The second
.pub
suffix is the public key. We use Notepad to open it and copy the contents.
- Then paste it into the public key column of the website you just mentioned. Just write the title as you like.
- Finally, use ssh to clone
- OK, you can see that it has been successful~~
push【push】
- We modify the files in the warehouse
- and then add
- The last critical step is
push
git push origin master
- Then check the remote warehouse and you can see that it has been modified.
Pull【pull】
- We first directly modified the remote warehouse
- This time we made local modifications again, and then added
- Finally, I performed the submission operation and found that it could not be submitted because there would be a conflict.
- At this time, we need to first pull the remote warehouse
git pull origin master
- Here we are back to the conflict, and then we need to manually modify it and then submit it.
- Then add and submit the operation
- You can see that it already exists~~
Configure git
ignore special files
-
In daily development, we don’t want to submit some files to the remote warehouse, so what should we do?
- At this time, we need to create a special file in the root directory of our warehouse
.gitignore
and fill in the file names that need to be ignored. These files will be automatically ignored when git submits~~
- At this time, we need to create a special file in the root directory of our warehouse
-
Let's demonstrate
-
The representative here
*
is a wildcard, that is,.txt
files with suffixes are ignored.
-
Let's check the status of git and see if there is any
文本.txt
-
Submit after adding again
- Come to our remote warehouse to check
- But sometimes, you just want to add a file to Git, but because the file is ignored by .gitignore and cannot be added at all, you can use -f to force the addition:
git add -f [filename]
- Or you find that there may be a problem with the writing of .gitignore, and you need to find out which rule is written wrong. For example, if the a.so file
is to be added, you can use the git check-ignore command to check:
git check-ignore -v file.txt
- Git will tell us which line of rules in .gitignore ignores the file, so we can know which rule should be revised.
There are also times when we write rules to exclude some files, for example:
# 排除所有.开头的隐藏⽂件:
.*
- But we found that the .* rule also excludes .gitignore. Although you can use git add -f to force it to be added, students with obsessive-compulsive disorder still hope not to break the .gitignore rules. At this time, you can add an exception rule:
# 排除所有.开头的隐藏⽂件:
.*
# 不排除.gitignore
!.gitignore
- The way to exclude specified files from .gitignore rules is
!
+ file name, so you only need to add the exception files.
Configure aliases for commands
-
When using git, sometimes the command is too long and too troublesome. We can rename the git command into a short one. We do this:
-
For example, we will
git status
abbreviate it asgit st
-
Change it here
alias.
to the name you want to change it to
git config --global alias.st status
-
--global
The parameters are global parameters, which means these commands are available in all Git repositories on this computer. If not added, it will only work for the current warehouse. -
In this way, the renaming can be successful, and the original name can also be used~~
tag management
Understand labels
- We can simply understand this label as
commit
an identification of a certain event, which is equivalent to an alias. - For things that are difficult to remember
commit id
, tags can solve this problem very well. Tags can locate an important version. Using tags, you can quickly locate that version, which is very convenient and fast.
Create tags
- First check which branch you are on. If you need to tag which branch you need to switch to, which branch should you switch to?
git branch
- Then you can add a tag, just follow the tag name.
git tag v1.0
- After tagging, you must check it
git tag
-
This tag is not specified on which one it should be printed on, so it is the default. By default, it is printed on
commit id
the latest submission.commmit
-
Then we need to
commit id
label the designation, and we can follow it withcommit id
git tag v0.9 741df88
Note: The tags here are not listed according to time, but are sorted alphabetically.
- We can also view tag information:
show
followed by the tag name, you can view specific information.
git show v1.0
- We can also specify tags with descriptions here, -a specifies the alias, and -m specifies the description text.
git tag -a [name] -m "XXX" [commit_id]
Action tag
- If the label is mistyped, we can also delete it
-d
followed by the label name.
git -d v0.8
-
Because the created tags are only stored locally and will not be automatically pushed to the remote. Therefore, mistyped tags can be safely deleted locally
-
If you want to push a label to the remote, you can use the command
git push origin <tagname>
-
We check the remote warehouse and see that the push has been successful.
-
If the local warehouse has many tags, they can be pushed to the remote end all at once.
git push oringe --tags
-
It’s also quite perfect and has been pushed up.
-
If you want to delete a tag, you must first delete it from the local warehouse, and then push it again to update it.
-
Just follow the colon with the name of the label~~
git push origin :v0.9
- Let’s go to the remote warehouse again
- It has been deleted perfectly~~
Well, the remote operation of git ends here. I hope everyone can master these skills. This is a great improvement in ability. I also hope everyone will study hard! come on!