Ubuntu16.04環境下git安裝與使用
一、git的安裝
參見廖雪峰的git教程,在Linux使用sudo apt-get install git即可。
二、建立本地版本庫
在需要建立版本庫進行管理的根資料夾下,輸入git init命令,通過git init命令將這個資料夾變成git可以管理的倉庫:
H:\>cd weekly-report
H:\weekly-report>git init
Initialized empty Git repository in H:/weekly-report/.git/
(注:這裡git init命令是在Windows系統下執行的,linux同樣類似)
可以看到:已經初始化了一個git倉庫,同時在該目錄下已經建立了一個.git目錄,這個目錄下的檔案包含了所有的配置檔案,注意千萬別手動更改.git目錄下的檔案,一旦修改會引起git倉庫的混亂。
這時, 在Ubuntu系統進入U盤檔案目錄後,重新輸入git init命令:
[email protected]:/media/vslyu-flash/weekly-report$ sudo git init
重新初始化現存的 Git 倉庫於 /media/vslyu-flash/weekly-report/.git/
提示已重新初始化現存的Git倉庫,使用ls -lah命令檢視包括隱藏檔案在內的詳細資訊:[email protected]:/media/vslyu-flash/weekly-report$ ls -lah 總用量 104K drwxr-xr-x 3 root root 8.0K May 16 15:48 . drwxr-xr-x 28 root root 8.0K Jan 1 1970 .. drwxr-xr-x 7 root root 8.0K May 16 17:25 .git -rwxr-xr-x 1 root root 79K May 6 21:23 週報-20180506-劉宇輝.docx
可以發現.git檔案的時間資訊已被改變,說明已被重新初始化。
三、同遠端倉庫如GitHub進行互動
參照廖雪峰的教程,因為本地Git倉庫和遠端GitHub倉庫之間的傳輸是通過SSH加密的,需要先配置SSH。
1、建立SSH Key
因為是第一次建立SSH Key,所以在主目錄裡並沒有.ssh目錄,驗證如下:
[email protected]:/$ sudo find / -name ".ssh"
/home/xuelingzhang/.ssh
find: `/run/user/1025/gvfs': 許可權不夠
find: `/run/user/1000/gvfs': 許可權不夠
[email protected] :/$
使用sshkeygen命令建立Key:[email protected]:/$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/yuhuiliu/.ssh/id_rsa):
Created directory '/home/yuhuiliu/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Passphrases do not match. Try again.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/yuhuiliu/.ssh/id_rsa.
Your public key has been saved in /home/yuhuiliu/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:cqfv09Sj7vxM3JnkEGX+p2w1pg+P/d88oFXqWRdlRNk [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| ==|
| +.E|
| . o.|
| .o.|
| . S . oo+=|
| o o .*O=*|
| . o++X=o|
| ..oo**o.|
| .o++oo+O|
+----[SHA256]-----+
[email protected]:/$
這裡會有兩個提示,首先提示你選擇save the key的路徑,預設選擇即可;需要注意的是其次兩次提示的ssh命令的密碼(該密碼是你push檔案的時候要輸入的密碼,而不是github管理者的密碼),為了方便,不設定密碼也可以。
2、登入GitHub填入client端生成的公鑰
ssh驗證的過程為:server端使用rsa.pub的公鑰對client發過來的rsa私鑰做匹配,匹配成功就能夠驗證成功。因此私鑰絕對不能洩露出去,否則就被別人冒充。 在這裡,GitHub就是在遠端的server端,只需要將上面生成的rsa公鑰上傳上去就可以了。
登入GitHub,在個人賬號那裡找到並開啟“settings”,點入“SSH and GPG keys”:
點選右上角的New SSH Key,進入建立SSH Key:
Title這裡取個名字,作為標識,一般我都是根據client端的名字來取名以示區別的;最後,在Key那裡貼上isa.pub公鑰檔案的內容即可。
可以使用文字編輯器如vi、gedit等開啟isa.pub檔案進行,也可以使用命令clip < ~/.ssh/id_rsa.pub進行復制:
在GitHub端貼上對應公鑰:
點選“Add SSH Key”即可建立成功。
3、測試一下該SSH Key
參照https://www.cnblogs.com/ayseeing/p/3572582.html,輸入ssh -T命令進行測試:
[email protected]:/$ ssh -T [email protected]
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
輸入yes即可,如果你在建立SSH Key是還設定了密碼,接下來還會提醒你輸入密碼;如果沒有,直接“Enter”即可,[email protected]:/$ ssh -T [email protected]
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yew
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
packet_write_wait: Connection to 52.74.223.119 port 22: Broken pipe
[email protected]:/$ ssh -T [email protected]
Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.
X11 forwarding request failed on channel 0
Hi vlsyu! You've successfully authenticated, but GitHub does not provide shell access.
[email protected]:/$
最後,看到上面紅色的歡迎字元表示你已經可以成功通過ssh連線到GitHub上。
三、同步本地庫到遠端庫上
應用場景:本地的倉庫需要推送到遠端倉庫上,一是進行備份,二是方便他人的開源。
1、在GitHub上建立一個新的倉庫,建議最好要與本地同名,不然同步的話會引起麻煩。
建立如圖的遠端倉庫:
目前在GitHub上面這個weekly-report倉庫並沒有內容,可以從其他的倉庫克隆到這個新的倉庫,也可以推送本地倉庫到這個倉庫。在這裡,我選擇推送之前在本地建立好的weekly-report倉庫到遠端weekly-report倉庫。
2、關聯本地倉庫到新的遠端GitHub倉庫
首先在本地的git倉庫下使用git remote add origin 命令新增對遠端倉庫的關聯:
[email protected]:/$ cd /media/vslyu-flash/weekly-report/
[email protected]:/media/vslyu-flash/weekly-report$ git remote add origin [email protected]:vslyu/weekly-report.git
error: could not lock config file .git/config: 許可權不夠
fatal: Could not set 'remote.origin.url' to '[email protected]:vslyu/weekly-report.git'
[email protected]:/media/vslyu-flash/weekly-report$ sudo git remote add origin [email protected]:vslyu/weekly-report.git
[sudo] yuhuiliu 的密碼:
[email protected]:/media/vslyu-flash/weekly-report$
新增成功後,在本地使用遠端倉庫的話遠端倉庫的名字就叫origin,當然也可以取其他名字,但是預設都取origin這個名字,這樣人一看就知道是遠端庫的名字。
3、推送本地倉庫到新的遠端GitHub倉庫上:
[email protected]:/media/vslyu-flash/weekly-report$ git push -u origin mastererror: src refspec master does not match any.
error: 無法推送一些引用到 '[email protected]:vslyu/weekly-report.git'
[email protected]:/media/vslyu-flash/weekly-report$ sudo git push -u origin master
error: src refspec master does not match any.
error: 無法推送一些引用到 '[email protected]:vslyu/weekly-report.git'
[email protected]:/media/vslyu-flash/weekly-report$
報了一個error,參照https://www.cnblogs.com/jeremylee/p/5715289.html,應該是git init後沒有往本地倉庫裡面新增檔案,使得無法提交一個空的倉庫。接下來往本地的庫裡新增檔案:[email protected]:/media/vslyu-flash/weekly-report$ sudo git add 週報-20180506-劉宇輝.docx
[email protected]:/media/vslyu-flash/weekly-report$
新增成功,繼續推送:[email protected]:/media/vslyu-flash/weekly-report$ sudo git push -u origin master
error: src refspec master does not match any.
error: 無法推送一些引用到 '[email protected]:vslyu/weekly-report.git'
發現還是報錯,使用git status檢視一下本地倉庫的狀態:[email protected]:/media/vslyu-flash/weekly-report$ git status
位於分支 master
初始提交
要提交的變更:
(使用 "git rm --cached <檔案>..." 以取消暫存)
新檔案: "\345\221\250\346\212\245-20180506-\345\210\230\345\256\207\350\276\211.docx"
本地倉庫已經不是一個空庫,再仔細檢查一下報的error,發現遠端倉庫中的名字“[email protected]:vslyu/weekly-report.git”拼錯了。(補充一個小技巧:遠端倉庫的名字一般可以直接從遠端專案主頁上進行copy)
移除繫結的origin,重新繫結:
- 修改命令(git remote set-url --add origin URL)
- 先移除後繫結
- 修改config配置檔案
[email protected]:/media/vslyu-flash/weekly-report$ sudo git remote set-url --add origin [email protected]:vlsyu/weekly-report.git
[sudo] yuhuiliu 的密碼:
[email protected]:/media/vslyu-flash/weekly-report$ sudo git push -u origin master
error: src refspec master does not match any.
error: 無法推送一些引用到 '[email protected]:vslyu/weekly-report.git'
error: src refspec master does not match any.
error: 無法推送一些引用到 '[email protected]:vlsyu/weekly-report.git'
這時再仔細檢視問題,發現add後沒有commit,commit一下:[email protected]:/media/vslyu-flash/weekly-report$ sudo git commit -m "[email protected],20180506"
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got '[email protected](none)')
[email protected]:/media/vslyu-flash/weekly-report$
根據提示配置一下email和name:[email protected]:/media/vslyu-flash/weekly-report$ sudo git config --global user.email "[email protected]"
[email protected]:/media/vslyu-flash/weekly-report$ sudo git config --global user.name "vslyu"
[email protected]:/media/vslyu-flash/weekly-report$
重新commit一下:[email protected]:/media/vslyu-flash/weekly-report$ sudo git commit -m "[email protected],20180506"
[master (根提交) b59f287] [email protected],20180506
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 "\345\221\250\346\212\245-20180506-\345\210\230\345\256\207\350\276\211.docx"
[email protected]:/media/vslyu-flash/weekly-report$
這下子終於提交了,再來push一下:
[email protected]:/media/vslyu-flash/weekly-report$ sudo git push -u origin master
The authenticity of host 'github.com (13.229.188.59)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
相關推薦
Ubuntu16.04環境下git安裝與使用
一、git的安裝 參見廖雪峰的git教程,在Linux使用sudo apt-get install git即可。二、建立本地版本庫 在需要建立版本庫進行管理的根資料夾下,輸入git init命令,通過git init命令將這個資料夾變成git可以管理的倉庫:H:\
Ubuntu16.04環境下命令列安裝驅動
去官網查適合自己的GPU驅動: 依次執行如下語句安裝: sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt-get up
Ubuntu16.04環境下安裝CUDA、cudnn、Caffe、Tensorflow、pytorch
【主題】Ubuntu16.04環境下安裝CUDA、cudnn、Caffe、Tensorflow、pytorch 【環境】 筆記本: 筆記本:惠普 Pavilion NoteBook 系統環境:Ubuntu16.04+Win10 64位雙系統 顯示卡:NVIDIA GT
Ubuntu16.04環境下PyTorch簡易安裝教程
安裝NVIDIA GPU顯示卡驅動 如果需要安裝cuda版本的PyTorch,電腦也有獨立顯示卡的時候,一般需要更新一下Ubuntu獨立顯示卡驅動。否則即使安裝了cuda版本的PyTorch也沒辦法使用GPU。 因為我的膝上型電腦顯示卡是NVIDIA的,所以
Caffe學習1——在ubuntu16.04環境下安裝Caffe(CPU)
目前在網上,已經存在很多的Caffe安裝教程。本文主要介紹筆者在安裝Caffe——CPU版本所遇到的問題(主要參考了網上的 部落格) ,以及相關解決方法。以下給出基於ubuntu 16.04系統的Caffe的CPU安裝步驟:1. 安裝gitsudo apt-get inst
Ubuntu16.04環境下MySQL5.7安裝&配置以及遠端訪問
mysql> set character_set_client=utf8; mysql> set character_set_connection=utf8; mysql> set character_set_database=utf8; mysql> set charact
Hyperledger fablic 0.6 在centos7環境下的安裝與部署
maker ber gin sudo 管理 lease nts eve blank 原文:http://blog.csdn.net/zhaoliang1131/article/details/54617274 Hyperledger Fabric超級賬本 項目約定共同遵守
Ubuntu環境下GitHub安裝與使用
process 兩種 ted 上傳 config err touch .com cte 安裝git sudo apt-get update sudo apt-get install git 1 2 1 2 配置 你的github git config --glo
Nginx在windows環境下的安裝與簡單配置
erro send apache pdf lpad 首頁 調用 技術 ase 每天學習一點點 編程PDF電子書、視頻教程免費下載: http://www.shitanlife.com/code 一. 下載並安裝Nginx 去Nginx官網下載 我這裏選取nginx
Linux & Windows 環境下 RabbitMQ 安裝與基本配置
web tor tag ogr 使用 sts 管理員 pin ini 索引: 開源Spring解決方案--lm.solution 參看代碼 GitHub: rabbitmq.txt 一、Linux (DeepinOS) 環境 1 1.安裝: 2 su
Ubuntu16.04環境下通過Cmake管理Opencv專案
Ubuntu16.04環境下通過Cmake管理Opencv專案 1、新建qt cmake工程 New Project -> Non-Qt Project -> Plain C++ Application 2、CMakeLists.txt檔案內
Ubuntu16.04環境下搭建Hadoop3.0.3偽分散式叢集
最近剛好趕上雙11騰訊促銷,於是搶購了一個8核16G記憶體的雲伺服器,加上業務上需要用到hadoop,hive,於是想搭建搭建一個hadoop分散式叢集,但是限於自己手頭上伺服器數量不多,因此打算先搭建一個hadoop偽分散式叢集。 首先介紹一下我的安裝
win環境下MongoDB安裝與配置成auth驗證服務
今天重新安裝了MongoDB(Windows),並且想要把它配置成需要驗證使用者密碼的服務。 1.官網上獲取msi檔案並安裝 MongoDB社群版 下載完成後直接執行msi檔案 注意要選擇custom 之後就一直next即可(記得不要勾選install com
Windows環境下git安裝搭建
1.Maven安裝 Maven的使用時基於JDK的,所以首先安裝JDK,JDK安裝步驟不在此文件中包含。 從伺服器上下載maven檔案,完成後解壓在某路徑下。 配置maven環境變數: 1.1新建 系統環境變數MAVEN_HOME 節點,如圖所示: 1.2在
Ubuntu 16.04環境下Kdevelop安裝和配置
哈哈哈 Kdevelop是一個很棒的IDE, 不僅是因為他免費也是因為它在Ubuntu的原始檔中提供了, 所以呢,只需要敲幾行程式碼就可以輕鬆下載啦。 我在這裡再濃縮下,提煉下精華: 安裝cmake:sudo apt-get install cmake
Android——離線開發環境下的安裝與配置
前提jdk安裝並且配置成功。參考部落格https://blog.csdn.net/t_yoo_csdn/article/details/79726772一, gradle方法1:(驗證可以)在工程目錄\gradle\wrapper\gradle-wrapper.propert
Windows環境下Maven 安裝與環境變數配置
Maven是一個專案管理的Java工具,我們可以使用Maven方便地管理團隊合作的專案,使用Maven可以管理類庫,有效方便地供團隊中的其他人員使用。 一、下載Maven Maven的官網下載地址:http://maven.apache.org/download.cgi 我下載
[joysticke]使用Ubuntu16.04環境下讀取USB手柄/方向盤資訊
1.獲取裝置的埠 在插入裝置時,在/dev/input目錄下 ,作業系統會為每一個裝置分配event號,先插上的為event0,後插上的為event1。 查詢裝置的裝置號用如下指令: cat /proc/bus/input/devices 獲得如下輸出 1 I: Bus=0
Ubuntu16.04環境下Python下xlearn機器學習庫的配置
一、xlearn的簡介參見:https://www.zhihu.com/question/37256015/answer/268151326,http://www.sohu.com/a/206728248_206784 在機器學習裡,除了深度學習和樹模型 (GB
centos7環境下RabbitMQ安裝與配置
RabbitMQ是流行的開源訊息佇列系統,是AMQP(Advanced Message Queuing Protocol高階訊息佇列協議)的標準實現,用erlang語言開發。RabbitMQ據說具有良好的效能和時效性,同時還能夠非常好的支援叢集和負載部署,非常適合在較大規模的分散式系統中使用,具體使用場景請參