Novice git usage records


foreword

A few years ago, I learned how to use git in school. After graduation, the company used tfs. This thing is really good. I feel that git is still easy to use, so let’s
learn it briefly.


1. Download and install git

Official website download: >>Click me! I point! <<

This is fine for a normal windows system computer:
insert image description here

After downloading, choose the installation location, and the next step is just fine

Tips: If you want to know the installation location of some software in the windows system, enter in the cmd console: where [name]
For example: where git
screenshots are as follows↓↓↓
insert image description here

Just open a directory, right-click the mouse, if there is a Git Bash Here menu, it means ok,
click to enter the git command line page (very similar to the liunx operation interface)
insert image description here

Two, use git

1. Basic concepts

↓↓↓The picture below is from the noble rookie tutorial: It’s easy to use! ↓↓↓

insert image description here

Remote warehouse (github, gitee, gitlab and other online warehouses)

Local warehouse (that is your git software, use push to submit to remote warehouse)

Temporary storage area/cache area (changes that have not been submitted to the local warehouse when the error is reported, can be committed to the local warehouse)

Workspace/local code (your code, new and changed code can be submitted to the temporary storage area using add)

2.git initialization settings

The remote warehouse can only be connected after the initial settings
. Set the name and email [If the login method uses ssh verification, it seems that the name and email can be written casually, but it is recommended to use the remote warehouse account and email]

git config --global user.name "yink"
git config --global user.email [email protected]

【
在 Windows 系统上,Git 会找寻用户主目录下的 .gitconfig 文件。主目录即 $HOME 变量指定的目录,一般都是 C:\Documents and Settings\$USER。
如果用了 --global 选项,那么更改的配置文件就是位于你用户主目录下的那个,以后你所有的项目都会默认使用这里配置的用户信息。
如果要在某个特定的项目中使用其他名字或者电邮,只要去掉 --global 选项重新配置即可,新的设定保存在当前项目的 .git/config 文件里
】

git config --list 【查看配置】

Configure the ssh key for identity verification (the account password I entered when I used Code Cloud)

Execute the following command in the git command window

ssh-keygen -t rsa 

Then press Enter three times in a row. If there is no problem, you will see the following interface.
Enter the command to view your key

cat ~/.ssh/id_rsa.pub

insert image description here

Copy the key to the remote warehouse website. I use gitlab, and the others should be the same.
insert image description here
After adding, you can verify whether it is successful on the git command line:

ssh -T [email protected]
【lykgit.com:这个是我本地部署的gitlab,更换成你对应网站的,比如gitee啥的】

Successful screenshot (in fact, I didn’t understand it, maybe it failed, hahaha, I can submit the code anyway~):insert image description here

3. Basic operation

3.1. Pull the remote warehouse code and submit it after modification

Create a new remote warehouse on the website, use clone locally to pull the warehouse to the local, modify the code and submit

git clone [url] 【拷贝一个 Git 仓库到本地】
eg:git clone git://github.com/schacon/grit.git
【在当前克隆远程仓库到本地仓库,在当前目录】

git status
git add *.txt
git add README
git commit -m "初始化项目版本"
【以上命令,显示有变更的文件,将目录下以 .txt 结尾及 README 文件提交到本地仓库中。】
【在 Linux 系统中,commit 信息使用单引号 ',Windows 系统,commit 信息使用双引号 "】

git push
【将本地代码提交到远程仓库】

After success, you can view your own code under the corresponding branch of the website.
insert image description here

3.2. Create a new branch and submit


git branch
git branch mybaranch
git checkout mybaranch
git push --set-upstream origin mybaranch
【上面代码解释:查看所有分支,创建一个名叫mybaranch分支,切换到mybaranch分支,提交mybaranch分支,第一次提交需要在远程上面创建这个分支,所有加了参数,后面提交只需要输入git push即可】


Summarize

Reference:
https://www.runoob.com/git/git-branch.html

Guess you like

Origin blog.csdn.net/lyk520dtf/article/details/131101575