GitHub 上傳及下載代碼
github是開源的代碼管理工具,同時也是一個很好的開源學習平臺,學習如何使用github也是非常重要的,以下是我梳理的一些常用的命令
配置
首先初次運行配置全局的用戶名和密碼,不然以後每次添加都需輸入用戶名和密碼這樣比較繁瑣,在打開的git shell中輸入這個,替換裏面的[username]和[email]
git config –global user.name [username]
git config –global user.email [email]
可以通過git config –list命令查看當前gitshell的一些設置
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
..........
初始化
配置完成之後,進入你的目錄,先運行一個初始化命令
git init
添加
接下來就是你要添加的文件,用git add命令
git add . (表示添加所有改變)
- git add . :他會監控工作區的狀態樹,使用它會把工作時的所有變化提交到暫存區,包括文件內容修改(modified)以及新文件(new),但不包括被刪除的文件。
- git add -u :他僅監控已經被add的文件(即tracked file),他會將被修改的文件提交到暫存區,add -u 不會提交新文件(untracked file)。(git add –update的縮寫)
- git add -A :是上面兩個功能的合集(git add –all的縮寫)
- git add後面接文件或者文件夾則會將這個文件或者文件夾提交
提交註釋
git commit -m 提交註釋文件,說明本次修改的內容和其他說明
git commit -m “需要說明的內容”
再提交之前需要用git status 命令擦好看裏面提交內容的變化,確認後再提交
關聯respositories
接下來也是比較重要的一步關聯github的項目可以進入需要添加的項目複製裏面的URL
在gitshell中運行以下命令,這樣其實origin就代表這個地址 https://github.com/*/MapReduce 當然你也可以用其他的名字如origin2等等,或者添加多個respositories,在push的時候添加對應的變量名稱就行了;
git remote add origin https://github.com/*/MapReduce
向respositories push更新
最後一步就是push命令了
輸入以下命令提交修改,其中後面的master表示版本號,origin是前面取得remote地址的名字提交之後後顯示,表示push成功。
git pull origin master
$ git push -u origin
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 402 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/HubSKY/MapReduce
5886228..82bf299 master -> master
Branch master set up to track remote branch master from origin2.
pull拉取修改,更新本地
下載同步代碼就是pull命令
git pull origin master
$ git pull origin master
From github.com:HubSKY/MapReduce
* branch master -> FETCH_HEAD
5886228..82bf299 master -> origin/master
Already up-to-date.
用gitshell管理很方便,git shell還包含分支創建,合併和刪除等,這裏就不一一細講,以上這些命令就足夠平常我們這些人使用了