手把手教你如何上傳代碼到gitee服務器


之前編寫了幾個適合新手的小項目,
為方便大家學習和下載代碼,
決定把代碼上傳到gitee服務器。

不得不說,git是一個非常好用的代碼版本管理工具,

本文手把手教大家如何將自己編寫的代碼上傳到Gitee。

1. 注冊賬號

打開網頁

https://gitee.com/


點擊注冊,
輸入一個自己喜歡的域名,yikoulinux
輸入手機號,驗證即可

點擊注冊並綁定 即可。

2.綁定微信

點擊頭像->設置

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

2. 綁定郵箱

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

點擊頭像->設置

點擊 左邊郵箱管理->新增
然后輸入剛才設置的gitee登錄密碼

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

點擊確定
在這里插入圖片描述

然后登錄自己郵箱,點擊對應的鏈接即可。

3. 新建倉庫

點擊頭像左側的+ -> 新建倉庫

輸入名稱以及開源許可證等。
 點擊創建即可。

4. clone克隆倉庫到本地

復制倉庫鏈接:

進入ubuntu
如果沒有安裝git,可以執行以下命令安裝git

sudo apt-get install git

配置git全局環境

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

修改commit默認打開的文本編輯工具

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

拷貝代碼到當前目錄

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

執行commit

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

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

上傳到服務器:

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

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

最終在gitee上顯示結果:


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

5. 常用git命令

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

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

(1)生成ssh密鑰

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

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

(2)上傳公鑰

使用命令cd ~/.ssh進入~/.ssh文件夾,輸入

cat id_rsa.pub

打開id_rsa.pub文件,復制其中所有內容。接着訪問git網頁,點擊SSH公鑰,標題欄可以隨意輸入,公鑰欄把剛才復制的內容粘貼進去。


此外,一口君還創建了一個基於Linux的聊天室的開源項目
基功能包括登錄、注冊、公聊、私聊、數據庫、數據加密等功能。
其他功能后續會陸續完善。

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

最后歡迎各位給我的開源項目點個星!

感謝了!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM