Ubuntu 18.04 環境下git安裝與使用

參考:

https://blog.csdn.net/vslyu/article/details/80337675

 

一、安裝

sudo apt-get install git

驗證是否安裝成功

(base) zywvvd@zywvvd-System-Product-Name:~/vvd_git$ git version
git version 2.17.1

二、文檔

man git 可以獲得所有的命令和參數的基本描述

三、基本操作

  1. 創建本地倉庫

在需要建立倉庫的路徑下

git init

將該文件夾變成git可以管理的文件夾。

(base) zywvvd@zywvvd-System-Product-Name:~/vvd_git$ git init
已初始化空的 Git 倉庫於 /home/zywvvd/vvd_git/.git/

可以看到在當前文件夾下新建了.git的隱藏文件夾

(base) zywvvd@zywvvd-System-Product-Name:~/vvd_git/.git$ ll
總用量 40
drwxr-xr-x 7 zywvvd zywvvd 4096 1月  21 11:21 ./
drwxr-xr-x 3 zywvvd zywvvd 4096 1月  21 11:21 ../
drwxr-xr-x 2 zywvvd zywvvd 4096 1月  21 11:21 branches/
-rw-r--r-- 1 zywvvd zywvvd   92 1月  21 11:21 config
-rw-r--r-- 1 zywvvd zywvvd   73 1月  21 11:21 description
-rw-r--r-- 1 zywvvd zywvvd   23 1月  21 11:21 HEAD
drwxr-xr-x 2 zywvvd zywvvd 4096 1月  21 11:21 hooks/
drwxr-xr-x 2 zywvvd zywvvd 4096 1月  21 11:21 info/
drwxr-xr-x 4 zywvvd zywvvd 4096 1月  21 11:21 objects/
drwxr-xr-x 4 zywvvd zywvvd 4096 1月  21 11:21 refs/

目錄中包含了該倉庫的配置文件,不要輕易手動修改

2、鏈接GitHub

  • 配置Git,配置指令爲 git config
git config --global user.name "zywvvd"
git config --global user.email "[email protected]"

查看git 配置

查看系統(system)配置:  git config --system --list

查看當前用戶(global)配置: git config --global  --list

查看當前倉庫配置信息: git config --local  --list

  • 生成ssh公鑰

使用命令:# ssh-keygen -t rsa -C "your email"

~/vvd_git$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/zywvvd/.ssh/id_rsa): 
Created directory '/home/zywvvd/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/zywvvd/.ssh/id_rsa.
Your public key has been saved in /home/zywvvd/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:klt1J9JxcGBj7xgB5dC1cXsQmK9ioOhInLRgqKppO8k [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|      o+p+=o+.   |
|       B.Bo+ o   |
|      = *.+ . .  |
|.    o = *.  .   |
|oo  . . u..      |
|* +   . .        |
|+*.. . .         |
|*E  .  .   .     |
|Ooo              |
+----[SHA256]-----+
  • 設置github

登陸github(沒有賬號需要申請 github.com)

在settings中設置 'SSH and GPG keys'

添加new SSH key—— 設置名字並將isa.pub公鑰文件的內容複製進去

  • 測試SSH Key
ssh -T [email protected]
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
Hi zywvvd! You've successfully authenticated, but GitHub does not provide shell access.

出現歡迎字段說明測試成功。

3、同步本地庫到遠程庫上

在github端建立倉庫 example.git

命令remote鏈接倉庫

git remote add origin https://github.com/zywvvd/example.git

編輯本地庫內容,推送到遠程端

echo "#example" >> README.md
git add README.md
git commit -m "README.md created"
git push -u origin master

此時可以在github端看到我們更新上傳的說明文件

4、克隆倉庫

執行如下命令以創建一個本地倉庫的克隆版本:
git clone /path/to/repository
如果是遠端服務器上的倉庫,你的命令會是這個樣子:
git clone username@host:/path/to/repository

 

發佈了24 篇原創文章 · 獲贊 92 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章