• 正文
    • 1. 注冊賬號
    • 2.綁定微信
    • 2. 綁定郵箱
    • 3. 新建倉庫
    • 4. clone克隆倉庫到本地
    • 5. 常用git命令
    • 6. 如果不想每次都輸入用戶名密碼可以
  • 相關(guān)推薦
申請入駐 產(chǎn)業(yè)圖譜

手把手教你如何上傳代碼到gitee服務(wù)器

02/06 15:18
398
加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點(diǎn)資訊討論

之前編寫了幾個(gè)適合新手的小項(xiàng)目,為方便大家學(xué)習(xí)和下載代碼,決定把代碼上傳到gitee服務(wù)器。

不得不說,git是一個(gè)非常好用的代碼版本管理工具,本文手把手教大家如何將自己編寫的代碼上傳到Gitee。

1. 注冊賬號

打開網(wǎng)頁:https://gitee.com/

點(diǎn)擊注冊,輸入一個(gè)自己喜歡的域名,yikoulinux輸入手機(jī)號,驗(yàn)證即可

點(diǎn)擊注冊并綁定 即可。

2.綁定微信

點(diǎn)擊頭像->設(shè)置

然后會彈出二維碼,用自己的微信掃描二維碼即可。

2. 綁定郵箱

后續(xù)版本管理操作需要綁定郵箱才能繼續(xù)操作。

點(diǎn)擊頭像->設(shè)置

點(diǎn)擊 左邊郵箱管理->新增然后輸入剛才設(shè)置的gitee登錄密碼

正確會進(jìn)入下面頁面, 輸入自己的郵箱(一口君用的QQ郵箱)

點(diǎn)擊確定

然后登錄自己郵箱,點(diǎn)擊對應(yīng)的鏈接即可。

3. 新建倉庫

點(diǎn)擊頭像左側(cè)的+ ?-> ?新建倉庫

輸入名稱以及開源許可證等。點(diǎn)擊創(chuàng)建即可。

4. clone克隆倉庫到本地

復(fù)制倉庫鏈接:

進(jìn)入ubuntu
如果沒有安裝git,可以執(zhí)行以下命令安裝git

sudo?apt-get?install?git

配置git全局環(huán)境

git?config?--global?user.name?"yikoulinux"
git?config?--global?user.email?"7335817@qq.com"

修改commit默認(rèn)打開的文本編輯工具

git?config?--global?core.editor?"vim"

開始克隆:

root@ubuntu:/home/peng/work#?git?clone?https://gitee.com/yikoulinux/encryption.git
Cloning?into?'encryption'...
remote:?Enumerating?objects:?4,?done.
remote:?Counting?objects:?100%?(4/4),?done.
remote:?Compressing?objects:?100%?(4/4),?done.
remote:?Total?4?(delta?0),?reused?0?(delta?0),?pack-reused?0
Unpacking?objects:?100%?(4/4),?done.
Checking?connectivity...?done.

查看克隆下來的文件夾

root@ubuntu:/home/peng/work#?ls
encryption
root@ubuntu:/home/peng/work#?cd?encryption/
root@ubuntu:/home/peng/work/encryption#?ls
LICENSE

查看git log

root@ubuntu:/home/peng/work/encryption#?git?log
commit?5e0d6d12afb34a8082c6ef60f34f6e615c99746e
Author:?一口Linux?<10221187+yikoulinux@user.noreply.gitee.com>
Date:???Tue?Dec?21?13:57:19?2021?+0000

????Initial?commit

拷貝代碼到當(dāng)前目錄

root@ubuntu:/home/peng/work/encryption#?ls
key.c??key.h??LICENSE??main.c??README.md???

其中README.md是文檔說明,采用Markdown格式編寫。

添加源文件到本地倉庫:

root@ubuntu:/home/peng/work/encryption#?git?add?*
root@ubuntu:/home/peng/work/encryption#?git?status
On?branch?master
Your?branch?is?up-to-date?with?'origin/master'.
Changes?to?be?committed:
??(use?"git?reset?HEAD?<file>..."?to?unstage)

?modified:???LICENSE
?new?file:???README.md
?new?file:???key.c
?new?file:???key.h
?new?file:???main.c
?
Changes?not?staged?for?commit:
??(use?"git?add?<file>..."?to?update?what?will?be?committed)
??(use?"git?checkout?--?<file>..."?to?discard?changes?in?working?directory)

?modified:???.gitignore

執(zhí)行commit

root@ubuntu:/home/peng/work/encryption#?git?commit

添加commit 的 log信息【此時(shí)編輯工具是vim】

上傳到服務(wù)器:

root@ubuntu:/home/peng/work/encryption#?git?push
warning:?push.default?is?unset;?its?implicit?value?has?changed?in
Git?2.0?from?'matching'?to?'simple'.?To?squelch?this?message
and?maintain?the?traditional?behavior,?use:

??git?config?--global?push.default?matching

To?squelch?this?message?and?adopt?the?new?behavior?now,?use:

??git?config?--global?push.default?simple

When?push.default?is?set?to?'matching',?git?will?push?local?branches
to?the?remote?branches?that?already?exist?with?the?same?name.

Since?Git?2.0,?Git?defaults?to?the?more?conservative?'simple'
behavior,?which?only?pushes?the?current?branch?to?the?corresponding
remote?branch?that?'git?pull'?uses?to?update?the?current?branch.

See?'git?help?config'?and?search?for?'push.default'?for?further?information.
(the?'simple'?mode?was?introduced?in?Git?1.7.11.?Use?the?similar?mode
'current'?instead?of?'simple'?if?you?sometimes?use?older?versions?of?Git)

Username?for?'https://gitee.com':?yikoulinux
Password?for?'https://yikoulinux@gitee.com':?
Counting?objects:?6,?done.
Compressing?objects:?100%?(6/6),?done.
Writing?objects:?100%?(6/6),?2.28?KiB?|?0?bytes/s,?done.
Total?6?(delta?0),?reused?0?(delta?0)
remote:?Powered?by?GITEE.COM?[GNK-6.2]
To?https://gitee.com/yikoulinux/encryption.git
???5e0d6d1..484d5d4??master?->?master

其中會要求輸入用戶名(開頭設(shè)置的名字yikoulinux)密碼,密碼輸入時(shí)不會回顯。

最終在gitee上顯示結(jié)果:

這樣我們就成功的將本地代碼上傳到服務(wù)器了。

5. 常用git命令

git?clone?項(xiàng)目地址??拉項(xiàng)目
git?pull????拉代碼
git?push??提交到倉庫
git?init?指令初始化一個(gè)git倉庫
git?add?.添加文件
git?commit?-m?"注釋"提交至倉庫。
git?remote?add?origin?https://git.oschina.net/你的用戶名/項(xiàng)目名.
git,git?push?origin?master即可完成推送
git?checkout?master???切換到master分支

6. 如果不想每次都輸入用戶名密碼可以

(1)生成ssh密鑰

ssh-keygen?-C?'7335817@qq.com'?-t?rsa

會在用戶目錄~/.ssh/下建立相應(yīng)的密鑰文件。如果是管理員創(chuàng)建在目錄/root/.ssh/下。

(2)上傳公鑰

使用命令cd ~/.ssh進(jìn)入~/.ssh文件夾,輸入

cat?id_rsa.pub

打開id_rsa.pub文件,復(fù)制其中所有內(nèi)容。接著訪問git網(wǎng)頁,點(diǎn)擊SSH公鑰,標(biāo)題欄可以隨意輸入,公鑰欄把剛才復(fù)制的內(nèi)容粘貼進(jìn)去。

此外,一口君還創(chuàng)建了一個(gè)基于Linux的聊天室的開源項(xiàng)目,基功能包括登錄、注冊、公聊、私聊、數(shù)據(jù)庫、數(shù)據(jù)加密等功能。其他功能后續(xù)會陸續(xù)完善。

https://gitee.com/yikoulinux/chat.git

最后歡迎各位給我的開源項(xiàng)目點(diǎn)個(gè)星!感謝了!

相關(guān)推薦

登錄即可解鎖
  • 海量技術(shù)文章
  • 設(shè)計(jì)資源下載
  • 產(chǎn)業(yè)鏈客戶資源
  • 寫文章/發(fā)需求
立即登錄

公眾號『一口Linux』號主彭老師,擁有15年嵌入式開發(fā)經(jīng)驗(yàn)和培訓(xùn)經(jīng)驗(yàn)。曾任職ZTE,某研究所,華清遠(yuǎn)見教學(xué)總監(jiān)。擁有多篇網(wǎng)絡(luò)協(xié)議相關(guān)專利和軟件著作。精通計(jì)算機(jī)網(wǎng)絡(luò)、Linux系統(tǒng)編程、ARM、Linux驅(qū)動、龍芯、物聯(lián)網(wǎng)。原創(chuàng)內(nèi)容基本從實(shí)際項(xiàng)目出發(fā),保持原理+實(shí)踐風(fēng)格,適合Linux驅(qū)動新手入門和技術(shù)進(jìn)階。