The version at the time of creation of this article was Git-2.41.0, and the target was note storage and code repository. Some companies may use different settings.
a Git
1.1 What is Git
Git is a free, open source distributed version control system used for agile and efficient project processing and project version management. It was originally an open source version control software developed
to help manage kernel development. :Remote warehouse :Local warehouse :Staging area :Work areaLinux
Remote
Repository
Index / Stage
Workspace
1.2 Distributed version control system
SVN
, CVS
is a centralized version control system ,
- The version library is centralized on the central server
- Centralized version control systems must be connected to the Internet
- Workflow:
Get the latest version from the central server
and push it to the central server. - Advantages: Better permission management function, relatively simple operation, and can accurately control the permissions of each directory
- Disadvantages: Problems with the central server will affect everyone's work, and the speed and branch management are not as good as git
Git
Is a distributed version control system
- Without a central server, everyone’s computer is a complete version library;
- Even if you are not connected to the Internet, you can still submit it to the local warehouse and view all the past
log
(log files). When there is an Internet connection, you canpush
go to the remote location; - Workflow:
Modify the local version library
and push each modification to the other party. - Advantages: Very powerful branch management functions.
A hash algorithm is usedSHA-1
. This ensures the integrity of code content and reduces disruption to the repository in the event of disk failures and network problems. - Disadvantages: Permission management is inconvenient and requires the use of plug-ins
gitolite
orgitlab
.
1.3 GIt installation and configuration steps (detailed and cumbersome version)
First, go to GitHub
the official website git-scm.com and download the version suitable for your computer. Mine is a 64-bit Windows.
After downloading the installation package, run it.
Just use the default options during the installation process. If it can be modified, I will show it in the image below.
You can add two options. The first is to create a shortcut. The second is to add Git
bash in the Windows terminal. There is no need to check for updates every day (Check daily).
Create a shortcut in the start menu and directly default.
Use the Windows default terminal text editor.
Use the default branch repository name.
Accept third-party software. Git
Use Git
the bundled ssh
way to handle carriage returns .
Use the default terminal to have more flexible behavior MinTTY
in scrolling back, resizing windows, text fonts, and selecting settings . They are fast forward and merge, reposition, and fast forward only.
git pull
Right-click on any blank space - Git Bash Here
to enter Git
the command window
Well, this section is finally over.
1.4 Common Git commands
Global configuration
git config --list #查看git的配置信息
git config --global --list #查看git的全局配置信息(user.name、user.email)
git config --global user.name "user.name" #设置本机所有的Git仓库用户名
git config --global user.email "user.email" #设置本机所有的Git仓库邮箱
git config --global user.password "password" #配置文件一般C:\Users\Administrator的.gitconfig文件中,故一般不在配置文件中设置密码
git config --global --unset user.name #删除某个全局配置项
clear #清空
ssh-agent bash
ssh-add ~/.ssh/id_rsa.github
ssh-add ~/.ssh/id_rsa.gitee #将新的私钥加入到 SSH agent 中
touch ~/.ssh/config #多账号配置,生成config文件
ssh -T [email protected]
ssh -T [email protected] #SSH Key测试
cd E:
cd 文件夹 #进入不同位置
git init #将文件夹初始为仓库
git remote add origin [email protected]:仓库SSH #关联远程仓库
git remote add origin [email protected]:名字/仓库名字.git #名字是github注册的名字
git add 文件名 #将内容从工作目录添加到暂存区
git add . #将所有新增的文件都添加暂存区
git commit -m "分支名" #所有通过 git add 暂存的文件提交到本地仓库
git push -u origin master #上传文件,如果带有-u参数,则指定了默认的远程主机, 这样以后再推入时,可以简写为:git push
git push origin master #上传文件
git status #展示工作区及暂存区域中不同状态的文件
git reset HEAD 文件名 #从暂存区移除指定文件
git checkout -- 文件名 #从本地仓库恢复指定文件
git pull #拉取远程仓库的数据
git log #查看git历史提交日志
git reflog #查看git所有提交日志
1.5 Configuration sequence
- Set username and warehouse email
git config --global user.name "user.name"
git config --global user.email "user.email"
- Generate
Github
, (Gitee
addSSH Key
two carriage returns)
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "user.email"
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "user.email"
C:\Users\Administrator\.ssh
Generated below
- Since it only reads by default
id_rsa
, in order for toSSH
recognize the new private key, the new private key needs to be addedSSH agent
to
ssh-agent bash
ssh-add ~/.ssh/id_rsa.github
ssh-add ~/.ssh/id_rsa.gitee
- In order to facilitate the use of both
Github
, multiple accounts need to be configured and files generated.Gitee
Git
config
touch ~/.ssh/config
and fill in the file
#Default gitHub user Self
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa.github
# gitee
Host gitee.com
Port 22
HostName gitee.com
User git
IdentityFile ~/.ssh/id_rsa.gitee
Finish
2GitHub
2.1 Create library
Enter the official website https://github.com/ to register. If the speed is slow, you can use steam++ and other legal science to surf the Internet. Google Chrome's translation is better.
Click the plus sign in the upper right corner New repository
to create a new repository.
Next, let your computer clone a library you created, and synchronize the code on your computer to the GitHub
library you created.
2.2 Add SSH Key
Copy the content generated by 1.5 id_rsa.github.pub
into the SSH Key
Click OK
2.3 SSH Key test
Enter the following command, press Enter, enter yes, and press Enter again. Hi appears in the red box to indicate that the public key is added successfully:
ssh -T [email protected]
Don't forget yes! ! !
2.4 Initialize local warehouse
Select a folder as the local warehouse and open it in this folder. Git Bash
You can also use cd to enter the folder (the red box is the location)
and enter git init
to initialize the folder as a warehouse
. The following picture is displayed to indicate success.
2.5 Associated warehouse
Copy the warehouse SSH and enter to git remote add origin [email protected]:仓库SSH
associate with the remote warehouse
2.6 Upload files
Create a link in the folder where the file to be uploaded is located Bash Here
- add
add a folder - commit
mark the branch - push
push
git remote add origin [email protected]:名字/仓库名字.git #名字是github注册的名字
git add 文件名
git commit -m "分支名"
git push -u origin master
For example, I want to put the file into the branch of 3.md
my accountyanqiu12138
git_test_notes
main
First, you need to change the location of the local library Bash Here
, that is, 3.md
the folder where it is located, or use cd命令
the switch location in the run box to switch to the library location.
分别输入
cd D:
cd Code/Github
git add 3.md
git commit -m "main"
git push -u origin master
2.7 Upload files directly on GitHub
- Enter the warehouse and click the
Add file
-Create new file
button on the upper right side of the warehouse:
- Note that
.md
files with the suffix ending can only be formatted when you click to preview, otherwise it will be an ordinary text.
3. Click commit changes
(submit changes) after writing.
4. Extended description
It describes what was done in this submission. Writing notes is not required at all.
2.8 Batch operations
Batch operation refers to batching files to local or uploading.
2.8.1 Batch download
- Direct download: click on the upper right corner of the
Code
warehouse——Download ZIP
- Also click on the upper right corner of the warehouse
Clone or download
, copy the given address in the drop-down menu,Git Bash Here
enter the following code in the folder location you want to save, and it will be ready in a moment:
git clone 地址
2.8.2 Batch upload
- Upload directly
- Save the uploaded file in the local library, then
Git Bash Here
enter the following code,
git remote add origin [email protected]:名字/仓库名字.git #名字是github注册的名字
git add 文件夹名
git commit -m "分支名"
git push -u origin master
ThreeGitee
Gitee is the Chinese version of GitHub. It has slightly less code than Github, but it has stable access in China and is free for small teams of less than 5 people.
3.1 Create library
- Go to the official website to register Gitee
- Add email: "Account Settings" in the upper right corner
3.2 Add SSH Key
Copy the content generated by 1.5 id_rsa.gitee.pub
into the SSH Key
3.3 SSH Key test
Enter the following commands respectively, press Enter, enter yes, and press Enter again. Hi appears in the red box to indicate that the public key is added successfully:
ssh -T [email protected]
Don't forget yes! ! !
3.4 Initialize local warehouse
Select a folder as the local warehouse and open it in this folder. Git Bash
You can also use cd to enter the folder (the red box is the location)
and enter git init
to initialize the folder as a warehouse
. The following picture is displayed to indicate success.
2.5 Associated warehouse
Copy the warehouse SSH and enter to git remote add origin 仓库SSH
associate with the remote warehouse
2.6 Upload files
Create a link in the folder where the file to be uploaded is located Bash Here
- add
add a folder - commit
mark the branch - push
push
git add 文件名
git commit -m "分支名"
git pull --rebase origin master(第一次使用的库需要这样建立链接)
git push -u origin master (之后不需要-u)
For example, I want to put the file into the branch of 1.md
my account雁丘
gitee_test_notes
test
2.7 Gitee team collaboration
Management—Repository Member Management—Developer—Add Member—Copy Link
A collection of four error reporting causes and solutions
1. No such file or directory Enter Chinese symbols or involve switching drive letters
When it comes to switching drive letters, there are two steps: switching drive letters and switching paths.
cd D:
cd Code/Github
2. When initializing the git project, an error is reported: Reinitialized existing Git repository in indicates that it has been initialized.
Note: The appearance of .git
the folder indicates that the initialization is successful. Some versions are hidden by default. You can view the hidden items by displaying them in the upper right corner.
If you want to re-initialize, just .git
delete the file
or enter it in the console under the current file to ls-a
view. If there .git
is, use delete and rm -rf .git
then re-initialize. Just initialize it
3. Host key verification failed
Be careful not to hit two Enters in a row, but enter before the second Enter.yes
4. Nothing to commit, working tree clean
There is no file in the temporary storage area or the file has been git add
passed. Just modify the file casually.
5. ! [rejected] master -> master (fetch first) error: failed to push some refs to ‘github.com:yanqiu12138/git_test_notes.git’
The error is reported because each warehouse has a branch, which can also be understood as a small warehouse in a large warehouse. We are only related to the online remote warehouse, but not to a branch of the online remote warehouse, so we do not Legal submission
Enter in the terminal git pull --rebase origin master
to associate with the default branch master of the online remote warehouse you just created.
Then execute it again git push -u origin master
to upload our project file to the associated online remote file.
Five commonly used recommendations
5.1 Google Chrome translation and plug-in Octotree (need to bypass the wall)
Chrome translation is very convenient when using Github's all-English interface. Various pop-up windows, plug-ins, and drop-down menus can quickly and automatically translate the
plug-in Octotree Github's navigation bar.
You can find it at 设置
- 扩展程序
- Chrome应用商店
and apply it directly to
open the code base. I found that when the mouse overlay appears on the left side of the webpage
, the files of the library will be displayed in the form of a tree.
If an error occurs: This branch was either deleted or you don't have access to it. Please go to Settings to login with GitHub OAuth or input a GitHub access token. (This branch has been deleted or you do not have permission to access it. Please go to "Settings" to log in using GitHub OAuth or enter a GitHub access token.) This is because the
plug-in requires a github token when accessing, just create one and give it to him
Solution: Click Settings, click the key button
, select the expiration date, and there is no expiration time. Select all the selection range (enterprise users can do their own research, and if they are individuals, select all).
Copy the generated tokens
Paste it here and you're done.
5.2 TortoiseGit
5.2.1 TortoiseGit installation
Xiaobai uses Git Bash to maintain Gitee and GitHub artifacts. It is a client developed for the Git version control system. Git is a command line operation mode, while TortoiseGit is an interface operation mode.
- Download the official website https://tortoisegit.org/download/ Pay attention to download the corresponding language pack.
Install the language pack first
. In addition to modifying the path to the default,
enter the email of git.
You need to use Putty for subsequent configurations. It is selected by default. Click Finish.
5.2.2 TortoiseGit configuration
Right click on the warehouse, TortoiseGit - Settings, enter the configuration interface