This article for newbies completes the detailed deployment tutorial for beginners using Git+Github/GITEE for fools (including TortoiseGit configuration)

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
Insert image description here
Remote
Repository
Index / Stage
Workspace

1.2 Distributed version control system

SVN, CVSis a centralized version control system ,

  1. The version library is centralized on the central server
  2. Centralized version control systems must be connected to the Internet
  3. Workflow:
    Get the latest version from the central server
    and push it to the central server.
  4. Advantages: Better permission management function, relatively simple operation, and can accurately control the permissions of each directory
  5. Disadvantages: Problems with the central server will affect everyone's work, and the speed and branch management are not as good as git

GitIs a distributed version control system

  1. Without a central server, everyone’s computer is a complete version library;
  2. 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 can pushgo to the remote location;
  3. Workflow:
    Modify the local version library
    and push each modification to the other party.
  4. Advantages: Very powerful branch management functions.
    A hash algorithm is used SHA-1. This ensures the integrity of code content and reduces disruption to the repository in the event of disk failures and network problems.
  5. Disadvantages: Permission management is inconvenient and requires the use of plug-ins gitoliteor gitlab.

1.3 GIt installation and configuration steps (detailed and cumbersome version)

First, go to GitHubthe official website git-scm.com and download the version suitable for your computer. Mine is a 64-bit Windows.
GitHub official website
Insert image description here
Insert image description here
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.
Insert image description here
You can add two options. The first is to create a shortcut. The second is to add Gitbash in the Windows terminal. There is no need to check for updates every day (Check daily).
Insert image description here
Create a shortcut in the start menu and directly default.
Insert image description here

Use the Windows default terminal text editor.
Insert image description here
Use the default branch repository name.
Insert image description here
Accept third-party software. Git
Insert image description here
Use Gitthe bundled ssh
Insert image description here
Insert image description here
way to handle carriage returns .
Insert image description here
Use the default terminal to have more flexible behavior MinTTYin scrolling back, resizing windows, text fonts, and selecting settings . They are fast forward and merge, reposition, and fast forward only.
Insert image description here
git pull
Insert image description here
Insert image description here
Insert image description here

Insert image description here

Right-click on any blank space - Git Bash Hereto enter Gitthe command window
Insert image description here

Insert image description here
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

  1. Set username and warehouse email
git config --global user.name "user.name"      
git config --global user.email "user.email"
  1. Generate Github, ( Giteeadd SSH Keytwo 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\.sshGenerated below
Insert image description here

  1. Since it only reads by default id_rsa, in order for to SSHrecognize the new private key, the new private key needs to be added SSH agentto
ssh-agent bash
ssh-add ~/.ssh/id_rsa.github
ssh-add ~/.ssh/id_rsa.gitee

  1. In order to facilitate the use of both Github, multiple accounts need to be configured and files generated.GiteeGitconfig
touch ~/.ssh/config

Insert image description here
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 repositoryto create a new repository.
Insert image description here
Insert image description here

Insert image description here
Next, let your computer clone a library you created, and synchronize the code on your computer to the GitHublibrary you created.

2.2 Add SSH Key

Copy the content generated by 1.5 id_rsa.github.pubinto the SSH Key

Insert image description here

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]

Insert image description here
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)
Insert image description here
and enter git initto initialize the folder as a warehouse
. The following picture is displayed to indicate success.
Insert image description here

2.5 Associated warehouse

Insert image description here
Copy the warehouse SSH and enter to git remote add origin [email protected]:仓库SSHassociate with the remote warehouse
Insert image description here

2.6 Upload files

Create a link in the folder where the file to be uploaded is located Bash Here
Insert image description here
- addadd a folder - commitmark the branch - pushpush

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.mdmy accountyanqiu12138git_test_notesmain
Insert image description here
Insert image description here

First, you need to change the location of the local library Bash Here, that is, 3.mdthe 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 

Insert image description here
Insert image description here

2.7 Upload files directly on GitHub

  1. Enter the warehouse and click the Add file- Create new filebutton on the upper right side of the warehouse:
    Insert image description here
  2. Note that .mdfiles with the suffix ending can only be formatted when you click to preview, otherwise it will be an ordinary text.

Insert image description here

Insert image description here
3. Click commit changes(submit changes) after writing. Insert image description here
4. Extended descriptionIt describes what was done in this submission. Writing notes is not required at all.
Insert image description here

2.8 Batch operations

Batch operation refers to batching files to local or uploading.

2.8.1 Batch download

  1. Direct download: click on the upper right corner of the Codewarehouse——Download ZIP
    Insert image description here
  2. Also click on the upper right corner of the warehouse Clone or download, copy the given address in the drop-down menu, Git Bash Hereenter the following code in the folder location you want to save, and it will be ready in a moment:
git clone 地址

Insert image description here

Insert image description here
Insert image description here

2.8.2 Batch upload

  1. Upload directlyInsert image description here

Insert image description here

  1. Save the uploaded file in the local library, then Git Bash Hereenter 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

  1. Go to the official website to register Gitee
    Insert image description here
  2. Add email: "Account Settings" in the upper right corner
    Insert image description here

3.2 Add SSH Key

Copy the content generated by 1.5 id_rsa.gitee.pubinto the SSH Key

Insert image description here

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]

Insert image description here
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)
Insert image description here
and enter git initto initialize the folder as a warehouse
. The following picture is displayed to indicate success.
Insert image description here

2.5 Associated warehouse

Insert image description here

Copy the warehouse SSH and enter to git remote add origin 仓库SSHassociate with the remote warehouse
Insert image description here

2.6 Upload files

Create a link in the folder where the file to be uploaded is located Bash Here
Insert image description here
- addadd a folder - commitmark the branch - pushpush

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.mdmy account雁丘gitee_test_notestest
Insert image description here

Insert image description here
Insert image description here

2.7 Gitee team collaboration

Insert image description here
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

Insert image description here
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 .gitthe 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.
Insert image description here
If you want to re-initialize, just .gitdelete the file
or enter it in the console under the current file to ls-aview. If there .gitis, use delete and rm -rf .gitthen re-initialize. Just initialize it
Insert image description here

3. Host key verification failed

Insert image description here
Be careful not to hit two Enters in a row, but enter before the second Enter.yes

4. Nothing to commit, working tree clean

Insert image description here
There is no file in the temporary storage area or the file has been git addpassed. 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
Insert image description here

Enter in the terminal git pull --rebase origin masterto associate with the default branch master of the online remote warehouse you just created.
Then execute it again git push -u origin masterto 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
Insert image description here
plug-in Octotree Github's navigation bar.
You can find it at 设置- 扩展程序- Chrome应用商店and apply it directly to
Insert image description here
open the code base. I found that when the mouse overlay appears on the left side of the webpage
Insert image description here
, the files of the library will be displayed in the form of a tree.
Insert image description here
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
Insert image description here
Insert image description here
, 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).
Insert image description here
Copy the generated tokens
Insert image description here

Paste it here and you're done.

Insert image description here

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.

  1. Download the official website https://tortoisegit.org/download/ Pay attention to download the corresponding language pack.
    Insert image description here
    Install the language pack first
    Insert image description here
    Insert image description here
    . In addition to modifying the path to the default,
    Insert image description here
    Insert image description here
    Insert image description here
    Insert image description here
    enter the email of git.

Insert image description here
You need to use Putty for subsequent configurations. It is selected by default. Click Finish.
Insert image description here

5.2.2 TortoiseGit configuration

Right click on the warehouse, TortoiseGit - Settings, enter the configuration interface
Insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/yanqiu12138/article/details/131497917