1. 程式人生 > 其它 >gitee使用教程,建立專案倉庫並上傳程式碼

gitee使用教程,建立專案倉庫並上傳程式碼

 

文章目錄

 

一、關於gitee

gitee(中文名:碼雲 ,原名 Git@OSC)是開源中國推出的基於git的程式碼託管服務。
國內訪問GitHub速度比較慢,如果想託管自己的程式碼到雲端,gitee是個不錯的選擇,華為的鴻蒙2.0原始碼也是放在gitee上的。

二、安裝git

要使用gitee,需要先安裝git工具。
git

工具下載:https://git-scm.com/downloads

安裝完成後,在命令列輸入git --version可以檢視到git的版本。

右鍵選單也會出現相應的選單。

三、登入gitee

我們先在 gitee上註冊賬號並登入。
gitee官網:https://gitee.com/

四、生成SSH公鑰

由於我們的本地 git倉庫和 gitee倉庫之間的傳輸是通過SSH加密的,所以我們需要配置SSH公鑰

注:安裝了git工具,就可以使用ssh命令

開啟cmd命令列,輸入命令

ssh-keygen -t rsa -C "[email protected]"
 
  • 1

注意:這裡的[email protected]

只是生成的 sshkey 的名稱,並不約束或要求具體命名為某個郵箱。


按照提示完成三次回車,即可生成ssh key
可以看到,我們生成的公鑰檔案id_rsa.pub路徑:C:\User\Adminstrator/.ssh/id_rsa.pub
進入該目錄用文字編輯器開啟

即可看到SSH公鑰,下文中將會用到這個SSH公鑰。

五、配置SSH公鑰

gitee網站點選設定

點選SSH公鑰

輸入公鑰標題,拷貝剛剛的SSH公鑰到框中,點選確定

配置成功

六、建立一個專案

點選右上角的 +號,新建倉庫

如下,填寫倉庫資訊,最後點選建立即可。

七、克隆倉庫到本地

點選克隆/下載,然後點選SSH,複製git

連結

接著,在本地目錄空白處右鍵選單,點選Git Bash Here

輸入git clone 剛剛的git連結,如下

git clone [email protected]:linxinfa/mytest.git
 
  • 1


成功後,本地目錄即可看到克隆下來的README檔案。

八、關聯本地工程到遠端倉庫

有時候,我們可能是先在本地有了工程檔案,然後再在gitee上建立倉庫的。
此時,可在本地庫上使用命令 git remote add把它和 gitee的遠端庫關聯,如下

git remote add origin git@gitee.com:linxinfa/mytest.git
 
  • 1

如果在使用命令 git remote add時報錯:

git remote add origin git@gitee.com:linxinfa/mytest.git
fatal: remote origin already exists.
 
  • 1
  • 2

說明本地庫已經關聯了一個名叫 origin的遠端庫,此時,可以先用git remote -v檢視遠端庫資訊:

git remote -v
origin git@gitee.com:linxinfa/mytest.git (fetch)
origin git@gitee.com:linxinfa/mytest.git (push)
 
  • 1
  • 2
  • 3

我們可以刪除已有的遠端庫

git remote rm origin
 
  • 1

再關聯遠端庫

git remote add origin git@gitee.com:linxinfa/mytest.git
 
  • 1

九、新增檔案

在本地新增檔案,如下,新增一個AddFileTest.txt檔案。

十、執行git命令,提交檔案

開啟git,執行gitaddcommitpush命令,即可將本地檔案上傳到遠端倉庫。
注:常用的git命令見文章最後面。

重新整理gitee頁面,即可看到本地檔案已經上傳到```gitee``上了

十一、刪除倉庫

點選管理

點選刪除倉庫,根據提示輸入密碼即可

十二、常用的git命令

常用的git命令

git init                        #把當前目錄變成git可以管理的倉庫
git add readme.txt              #新增一個檔案,也可以新增資料夾
git add -A                      #新增全部檔案
git rm test.txt                 #刪除一個檔案,也可以刪除資料夾
git commit -a -m "some commit"  #提交修改
git status                      #檢視是否還有未提交
git log                         #檢視最近日誌
git reset --hard HEAD^          #版本回退一個版本
git reset --hard HEAD^^         #版本回退兩個版本
git reset --hard HEAD~100       #版本回退多個版本
git remote add origin +地址     #遠端倉庫的提交(第一次連結)
git push -u origin master       #倉庫關聯
git push                        #遠端倉庫的提交(第二次及之後)
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13



更多的git命令,可以輸入git --help檢視,或者訪問git命令手冊:https://git-scm.com/docs

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.
  轉自:https://www.dianjilingqu.com/