使用Git如何上傳代碼至github

git命令簡介

root@test:/tmp/huhaha# git --help
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
??clone ?? Clone a repository into a new directory
??init ?? Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
??add ?? Add file contents to the index
??mv ?? Move or rename a file, a directory, or a symlink
??restore ?? Restore working tree files
??rm ?? Remove files from the working tree and from the index
??sparse-checkout ?? Initialize and modify the sparse-checkout
examine the history and state (see also: git help revisions)
??bisect ?? Use binary search to find the commit that introduced a bug
??diff ?? Show changes between commits, commit and working tree, etc
??grep ?? Print lines matching a pattern
??log ?? Show commit logs
??show ?? Show various types of objects
??status ?? Show the working tree status
grow, mark and tweak your common history
??branch ?? List, create, or delete branches
??commit ?? Record changes to the repository
??merge ?? Join two or more development histories together
??rebase ?? Reapply commits on top of another base tip
??reset ?? Reset current HEAD to the specified state
??switch ?? Switch branches
??tag ?? Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
??fetch ?? Download objects and refs from another repository
??pull ?? Fetch from and integrate with another repository or a local branch
??push ?? Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.

git上傳代碼操作

  • 拉代碼到本地倉庫
#克隆一個代碼倉到當(dāng)前環(huán)境刁品,鏈接為你github上鏈接
#會提示你輸入用戶名加密碼,等待結(jié)束即可
root@test:/tmp# git clone http:path.git
Cloning into 'huhaha'...
Username for 'http://xx.xx.xx.xx': user name
Password for 'http://username@xx.xx.xx.xx': password
remote: Enumerating objects: 4066, done.
remote: Counting objects: 100% (4066/4066), done.
remote: Compressing objects: 100% (1673/1673), done.
remote: Total 4066 (delta 2372), reused 4040 (delta 2346)
Receiving objects: 100% (4066/4066), 4.72 MiB | 2.84 MiB/s, done.
Resolving deltas: 100% (2372/2372), done.

  • 創(chuàng)建或切換分支
#這里需要注意砰粹,要先切換一下路徑
root@test:/tmp# cd huhaha/
#打印一下當(dāng)前的枝干是主干還是分支
root@test:/tmp/huhaha# git branch
* master
#這里是切換分支操作
root@test:/tmp/huhaha# git checkout huhahah
Branch 'huhahah' set up to track remote branch 'huhahah' from 'origin'.
Switched to a new branch 'huhahah'
#可以看到分支切換過來了
root@test:/tmp/huhaha# git branch
  master
* huahahah

  • 拷貝代碼到當(dāng)前分支對應(yīng)目錄下劝赔,并將代碼添加到代碼倉
#把我新添加的代碼目錄拷貝到剛剛克隆的代碼倉里
root@test:/tmp/huhaha# cp -r /root/huhaha/scripts/test/ /tmp/huhaha/scripts/
#其他需要拷貝的
root@test:/tmp/huhaha# cd scripts/other
#添加代碼倉操作
root@test:/tmp/huhaha# git add .   #注意后面的“.”不能丟
#查看一下狀態(tài),添加成功則會變顏色
root@test:/tmp/huhaha# git status
On branch huhahah
Your branch is up to date with 'origin/huhahah'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    .......done

  • commit and push代碼
#在commit之前還需添加一下郵箱及用戶名
root@test:/tmp/huhaha# git config --global user.email "you@example.com"
root@test:/tmp/huhaha# git config --global user.name "Your Name"
#進(jìn)行commit操作谜悟,-m 描述信息
root@test:/tmp/huhaha# git commit -m "add compare case"
[huhahah ed38a60] add compare case
 34 files changed, 2006 insertions(+), 12 deletions(-)
  ......done

#push到github代碼倉
root@test:/tmp/huhaha# git push -u origin huhahah
Username for 'http://xx.xx.xx.xx': user name
Password for 'http://username@xxx.xx.xx.xx': password
Enumerating objects: 51, done.
Counting objects: 100% (51/51), done.
Delta compression using up to 24 threads
Compressing objects: 100% (44/44), done.
Writing objects: 100% (44/44), 12.30 KiB | 4.10 MiB/s, done.
Total 44 (delta 35), reused 0 (delta 0)
remote:
remote: To create a merge request for nvme_read_write, visit:
remote:   http://xx.xx.xx.xx/tester/huhaha/merge_requests/new?merge_request%5Bsource_branch%5D=huhahah
remote:
To http://xx.xx.xx.xx/tester/huhaha.git
   81424e3..ed38a60  huhahah -> huhahah
Branch 'huhahah' set up to track remote branch 'huhahah' from 'origin'.


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子窟却,更是在濱河造成了極大的恐慌遇汞,老刑警劉巖未妹,帶你破解...
    沈念sama閱讀 217,084評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異空入,居然都是意外死亡络它,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,623評論 3 392
  • 文/潘曉璐 我一進(jìn)店門歪赢,熙熙樓的掌柜王于貴愁眉苦臉地迎上來化戳,“玉大人,你說我怎么就攤上這事埋凯∮厮福” “怎么了看尼?”我有些...
    開封第一講書人閱讀 163,450評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長盟步。 經(jīng)常有香客問我藏斩,道長,這世上最難降的妖魔是什么却盘? 我笑而不...
    開封第一講書人閱讀 58,322評論 1 293
  • 正文 為了忘掉前任狰域,我火速辦了婚禮,結(jié)果婚禮上黄橘,老公的妹妹穿的比我還像新娘兆览。我一直安慰自己,他們只是感情好塞关,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,370評論 6 390
  • 文/花漫 我一把揭開白布抬探。 她就那樣靜靜地躺著,像睡著了一般帆赢。 火紅的嫁衣襯著肌膚如雪小压。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,274評論 1 300
  • 那天椰于,我揣著相機(jī)與錄音怠益,去河邊找鬼。 笑死瘾婿,一個胖子當(dāng)著我的面吹牛蜻牢,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播偏陪,決...
    沈念sama閱讀 40,126評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼抢呆,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了笛谦?” 一聲冷哼從身側(cè)響起镀娶,我...
    開封第一講書人閱讀 38,980評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎揪罕,沒想到半個月后梯码,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,414評論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡好啰,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,599評論 3 334
  • 正文 我和宋清朗相戀三年轩娶,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片框往。...
    茶點(diǎn)故事閱讀 39,773評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡鳄抒,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情许溅,我是刑警寧澤瓤鼻,帶...
    沈念sama閱讀 35,470評論 5 344
  • 正文 年R本政府宣布,位于F島的核電站贤重,受9級特大地震影響茬祷,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜并蝗,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,080評論 3 327
  • 文/蒙蒙 一祭犯、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧滚停,春花似錦沃粗、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,713評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至起惕,卻和暖如春涡贱,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背疤祭。 一陣腳步聲響...
    開封第一講書人閱讀 32,852評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留饵婆,地道東北人勺馆。 一個月前我還...
    沈念sama閱讀 47,865評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像侨核,于是被迫代替她去往敵國和親草穆。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,689評論 2 354

推薦閱讀更多精彩內(nèi)容