purpose
Manage github hosting project code through git;
Download and install
- Download from the official website: https://git-scm.com/downloads
- Double click to install
- Select the working directory for installation
- Select components
- Start menu directory name setting
- Choose to use the command line environment
- I gave up, I chose next all;
- Check whether the installation is successful: right-click on the desktop, if there is an option for two git words, it is successful;
Configure Git
Set global variables
Open git bush here with the right mouse button on the desktop:
enter:
$ git config --global user.name "your name"
$ git config --global user.email "[email protected]"
Log in to GitHub, create an SSHkey
Then enter this to create an SSHkey:
$ ssh-keygen -t rsa -C "[email protected]"
Then click the Enter key three times in a row;
a .ssh folder will be generated under the local user folder, which contains two files id_rsa and id_rsa.pub:
Then open the folder:
Then open id_rsa.pub with Notepad, select all, Copy:
Then we go back to the GitHub account we just registered, click Settings:
Then click SSH:
Then click NEW SSHkey:
Then paste the key copied in the previous step and add it to the GitHub account settings:
Then go back to git, enter:
$ ssh -T git@github.com
Finally, enter yes
:
OK, this completes the local and GitHub communication configuration.
Git basic workflow
Git work area
to add files to the warehouse process
Git initialization and warehouse creation and operation
Basic information settings
# 1.设置用户名
$ git config --global user.name '用户名'
# 2. 设置用户名邮箱
$ git config --global user.email '邮箱'
This setting shows who submitted the file on the github repository homepage;
Initialize a new Git repository
- Create a folder;
$ mkdir 文件名
- Initialize git in the file (create a git repository);
$ cd 文件名
$ git init
(If you can't see .git, set the computer to display hidden files)
Add files to the warehouse
# 创建 a1.php 文件
$ touch a1.php
$ git status
# 添加到暂存区
$ git add a1.php
$ git status
# 将文件从暂存区提交到仓库
$ git commit -m 'add a1.php'
$ git status
Modify warehouse files
$ ls
$ git status
$ vi a1.php
# 修改文件
$ cat a1.php
1111
$ git status
# 添加到暂存区
$ git add a1.php
$ git status
$ git commit -m '第一次通过git修改文件并提交到仓库'
$ git status
Delete warehouse files
# 删除文件
$ rm -rf a1.php
# 从Git中删除文件
$ git rm a1.php
# 提交操作
$ git commit -m '第一次通过git删除仓库文件'
$ git status
Git management remote warehouse
Purpose of using remote warehouse
Function: backup, realize centralized management of code sharing;
$ git status
# 创建文件
$ touch a2.php
$ git status
# 添加到暂存区
$ git add a2.php
$ git status
# 将文件从暂存区提交到本地仓库
$ git commit -m 'add a2.php'
$ git status
# 将本地仓库提交到远程仓库
$ git push
Git clone operation
- Purpose : Copy the remote warehouse (the project corresponding to github) to the local;
- Code :
$ git clone 仓库地址
Origin of warehouse address:
Sync local warehouse to git remote warehouse
$ git push
If it displays The requested URL returned error: 403 Forbidden while accessing
, it means there is no permission;
Generally, this situation is a private project, no permission, enter the user name and password, or the remote address uses this type:
$ vi .git/config
# 将
# [remote "origin"]
# url = https://github.com/用户名/仓库名.git
# 修改为:
# [remote "origin"]
# url = https://用户名:密码@github.com/用户名/仓库名.git
Below I use the project in VSCode as an example:
First of all, create a new warehouse on github with the same name as the local project:
enter the page as shown below, remember to click ssh:
but you can’t run git bash yet. When you use git clone or push command for the first time, connect to github will appear A warning, resulting in a dialogue:
Are you sure you want to continue connecting (yes/no)?
Because git uses ssh to connect, and when ssh connects to verify the github server key for the first time, you need to confirm whether the fingerprint information of the github server key really comes from the github server.
So we need to get an ssh key, and this step has been mentioned in the previous Git configuration;
So we open the following interface and copy the code line by line to git bash:
The new branch in the figure shows that the execution is successful:
Go back to the remote warehouse interface of github, refresh, and your own warehouse name appears to prove that the warehouse was successfully established:
Also, at the input git remote add origin **************
, I reported a fault:
fatal: remote origin already exists.(报错远程起源已经存在。)
The solution is as follows:
# 1、先输入
$ git remote rm origin
# 2、再输入
$ git remote add origin **************
Github Pages build website
Personal site
access
https://username.github.io
Build steps
- Create Personal Site -> New Warehouse (Note: The warehouse name must be
用户名.github.io
);
- Create a new index.hitml file under the warehouse;
- github pages only supports static web pages;
- Only html files in the warehouse;
Then I failed: I
don’t know why, harm;
Project Pages project site
access
https://username.github.io/warehouse name
Build steps
- Enter the project homepage and click settings;
- On the settings page, click [Choose a theme] to automatically generate a theme page:
Then my page has not been loaded, and I am mad at me, just write here first;
————————————————————————
Refer to two Zhihu articles:
Most of the pictures in the above steps are quoted from these two articles, and after I personally tried it, the final successful picture is the result of my own attempt;