Linux下Git和GitHub使用方法總結

來源:互聯網
上載者:User

1 Linux下Git和GitHub環境的搭建

第一步: 安裝Git,使用命令 “sudo apt-get install git”

第二步: 建立GitHub帳號

第三步: 產生ssh key,使用命令 “ssh-keygen -t rsa -C "your_email@youremail.com"”,your_email是你的email

第四步: 回到github,進入Account Settings,左邊選擇SSH Keys,Add SSH Key,title隨便填,粘貼key。

第五步: 測試ssh key是否成功,使用命令“ssh -T git@github.com”,如果出現You’ve successfully authenticated, but GitHub does not provide shell access 。這就表示已成功連上github。

第六步: 配置Git的設定檔,username和email

git config --global user.name "your name" //配置使用者名稱

git config --global user.email "your email" //配置email

 

2 利用Git從本地上傳到GitHub

第一步: 進入要所要上傳檔案的目錄輸入命令 “git init”

第二步: 建立一個本地倉庫origin,使用命令 “git remote add origin git@github.com:yourName/yourRepo.git”
youname是你的GitHub的使用者名稱,yourRepo是你要上傳到GitHub的倉庫

第三步: 比如你要添加一個檔案xxx到本地倉庫,使用命令 “git add xxx”,可以使用“git add .”自動判斷添加哪些檔案

然後把這個添加提交到本地的倉庫,使用命令 ”git commit -m ”說明這次的提交“ “

最後把本地倉庫origin提交到遠端GitHub倉庫,使用命令 ”git push origin master“

 

3 從GitHub複製項目到本地

第一步: 到GitHub的某個倉庫,然後複製右邊的有個“HTTPS clone url”

第二步: 回到要存放的目錄下,使用命令 "git clone https://github.com/chenguolin/scrapy.git",紅色的url只是一個例子

第三步: 如果本地的版本不是最新的,可以使用命令 “git fetch origin”,origin是本地倉庫

第四步: 把更新的內容合并到本地分支,可以使用命令 “git merge origin/master”

 

如果你不想手動去合并,那麼你可以使用: git pull <本地倉庫> master // 這個命令可以拉去最新版本並自動合并

 

4 GitHub的分支管理

建立

1 建立一個本地分支: git branch <新分支名字>

2 將本地分支同步到GitHub上面: git push <本地倉庫名> <新分支名>

3 切換到建立立的分支: git checkout <新分支名>

4 為你的分支加入一個新的遠程端: git remote add <遠程端名字> <地址>

5 查看當前倉庫有幾個分支: git branch

刪除

1 從本地刪除一個分支: git branch -d <分支名稱>

2 同步到GitHub上面刪除這個分支: git push <本地倉庫名> :<GitHub端分支>

 

5 常見錯誤

1 如果出現報錯為ERROR: Repository not found.fatal: The remote end hung up unexpectedly則代表你的 origin 的url 連結有誤,可能是建立錯誤,也可能是這個 git@github.com:xxx/new-project.git url 指定不正確。重新建立。

Git 的詳細介紹:請點這裡
Git 的:請點這裡

推薦閱讀:

如何在 GitHub 建立組織

GitHub Linux下使用方法

Windows下Eclipse搭建GitHub開發環境圖文教程

R語言 3.0.1 源碼已經提交到 GitHub

Git權威指南 PDF高清中文版

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.