How to use git under Linux? How to build your own library?

Preface:
This article mainly introduces how to Linux use in git , giteeaccount registration, how to create a remote warehouse and local warehouse, and gitcommon instructions of .

1. Install git

  1. Switch to the root user identity and enter the command:
 yum install -y git
  1. Use the ·sudo· command;
sudo yum install -y git

2. New warehouse

Enter Code Cloud , click the plus sign in the upper right corner, and select New Warehouse
insert image description here

Configure warehouse information

insert image description here

3. Clone the remote warehouse to the local

  1. Click Clone/Download
  2. chooseHTTPS
  3. select copy link

  1. Enter the command at the command line git cloneplus the copied link
git clone https://gitee.com/your-highness-p/the-use-of-git-in-linux.git
  1. Enter the code cloud account name (registered mobile phone number) and password (code cloud account password)
  2. Display the file list, and you will find that there is an additional directory with the same name as the remote warehouse under the current directory

insert image description here

4. How to use git to submit files to the remote warehouse

  1. git add: Add files to the staging area

  2. git commit: Submit the staging area to the local warehouse

  3. git push: Synchronize the contents of the local warehouse to the remote warehouse.

Now we enter the local warehouse and create a new file test.cpp with the following content:

$ cd the-use-of-git-in-linux
$ touch test.cpp
$ echo "hello world" > test.c
$ cat test.c

First, add the file to the staging area

git add test.c

Then, submit the staging area to the local warehouse

git commit -m "用于测试git"

-mThe following content is to make a description of this submission, for example: modify a bug, add code, binary tree practice questions, etc.

If you submit the code for the first time, you may encounter the following error report. The reason is that you need to configure the machine information. All Gitwarehouses on this machine will use this configuration.

insert image description here
Then add your homepage username and email address:

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

Then resubmit, if 1 file changed, 1 insertion(+)the words such as appear, the submission is successful.

insert image description here

Finally, synchronize the contents of the local warehouse to the remote warehouse

git push

This operation needs to fill in your code cloud account number and password, just enter it directly.

pushAfter that, you can see the content we just submitted in the remote warehouse.

insert image description here

5. A complete collection of git common instructions

gitMore operating instructions are organized below . As a beginner, the above three gitoperations are enough, but you will inevitably encounter many problems, so I won’t explain them in detail here~

//初始化一个Git仓库
git init  

//将所有修改添加到暂存区
git add .  
 
//将暂存区的修改提交到本地仓库 并填写注释信息
git commit -m "comment"  

//http:#邮箱(或用户名):密码@仓库 下载一个项目和它的整个代码历史
git clone http://123%40qq.com:[email protected]/xxx  
 
//将本地的 master 分支推送到远程的 master 分支中
git push origin master
 
//查看 git 的 commit 信息,每次提交的信息包括注释在内,从最新提交到最久提交
git log  
 
//将commit 信息简化成一行显示
git log --pretty=oneline  
 
//查看仓库的状态
git status  

//列出所有本地分支,-r 列出所有远程分支
git branch [-r]  

//新建一个分支,但依然停留在当前分支
git branch [branch-name]  

//新建一个分支,并切换到该分支
git checkout -b [branch] 

//切换到指定分支,并更新工作区
git checkout [branch-name]  

//删除分支
git branch -d [branch-name]  
 
//删除远程分支
git push origin --delete [branch-name]  
 
//下载远程仓库的所有变动
git fetch [remote]  

//增加一个新的远程仓库,并命名
git remote add [shortname] [url] 

//取回远程仓库的变化,并与本地分支合并
git pull [remote] [branch]  

//恢复暂存区的指定文件到工作区
git checkout [file] 

//重置暂存区的指定文件,与上一次commit保持一致,但工作区不变
git reset [file]  

This is the end of this article, the code text is not easy, please support me a lot! ! !

Guess you like

Origin blog.csdn.net/weixin_67401157/article/details/131606861