Git的使用

源碼安裝

  1. 訪問地址:https://git-scm.com/download/linux
    https://mirrors.edge.kernel.org/pub/software/scm/git/

  2. 找到最新版本的tar.gz包
    本次下載git-2.20.1.tar.gz

  3. 安裝git的依賴項
    [root@localhost ~]# yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
    [root@localhost yum.repos.d]# yum -y install gcc perl-ExtUtils-MakeMaker

  4. 移除已安裝的git
    [root@localhost ~]# yum remove git

  5. 解壓安裝包
    [root@localhost ~]# tar -zxvf git-2.20.1.tar.gz

  6. 進(jìn)入解壓目錄,預(yù)編譯git
    [root@localhost ~]# cd git-2.20.1
    [root@localhost git-2.20.1]# ./configure --prefix=/usr/local/git

  7. 編譯并安裝git
    [root@localhost git-2.20.1]# make && make install

  8. 將git的腳本軟連接到/usr/bin/目錄下
    [root@localhost git-2.20.1]# ln -s /usr/local/git/bin/* /usr/bin/

  9. 檢測是否安裝成功
    [root@localhost git-2.20.1]# git --version

全局配置
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"

與某遠(yuǎn)程倉庫關(guān)聯(lián)

  • 創(chuàng)建一個新倉庫
    git clone git@gitlab.whenling.com:root/blank-project.git
    cd blank-project
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master

  • 在已存在的文件夾下
    cd existing_folder
    git init
    git remote add origin git@gitlab.whenling.com:root/blank-project.git
    git add .
    git commit -m "Initial commit"
    git push -u origin master

  • 在已存在的倉庫下
    cd existing_repo
    git remote rename origin old-origin
    git remote add origin git@gitlab.whenling.com:root/blank-project.git
    git push -u origin --all
    git push -u origin --tags

本地與遠(yuǎn)程倉庫不一致時拉取
git pull origin master --allow-unrelated-histories

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容