隨筆—git的基本命令

git是一個非常優秀的版本控制系統,可以對各類大小的項目進行源代碼管理,

 #git的常用功能如下:
1、從服務器上克隆完整的Git倉庫(包括代碼和版本信息)到單機上。
2、在本地倉庫上根據不同的開發目的,創建分支,修改代碼。
3、在本機上向自己創建的分支上提交代碼。
4、在本機上合并分支。
5、將本地倉庫代碼和分支推送到服務器上的遠程倉庫

在官網下載最新版的git軟件,官網地址https://git-scm.com/downloads,本文以Windows下git使用為例,服務器端為已經安裝完成的Gitlab,此處僅為演示git的相關命令的用法。

  安裝完成后,鼠標右鍵菜單會出現Git GIT和Git Bash 選項,在本地倉庫目錄選擇Git Bash here,打開git命令窗口。

gitbash.png

1、初始化本地倉庫,使用git init命令初始化本地倉庫,初始化會在本地目錄內新建一個.git目錄

$ pwd         #查看本地工作路徑
/e/train
$ git init   #初始化倉庫
Initialized empty Git repository in E:/train/.git/

2、克隆服務器倉庫至本地

$ git clone ssh://****.****.com/train.git
Cloning into 'train'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.

3、將文件新增至暫存區

如果當前目錄下有新增的文件,需要先用 git add 命令告訴 Git 開始對這些文件進行跟蹤并放入暫時存區,然后提交

git add helloworld.html

4、此時檢查當前工作狀態可看到有文件待提交;如使用git reset HEAD命令,可將文件拉回未暫時存區,再次查看狀態時,文件名變紅色

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
        new file:   helloworld.html

5、提交新增文件到本地倉庫

git commit -m 'helloworld.html'

6、推送本地文件到遠程倉庫:git push

Administrator@Patrick MINGW64 /e/train/test1.0 (master)   #最后的master表示當前處于master分支
$ git push -u origin master    #master表示推送的是本地master分支  
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 606 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To http://*****/Test1.0.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

7、查看分支狀態:git branch。前帶*的為當前分支

$ git branch    #目前只有master一個分支
* master

8、新建分支

Administrator@Patrick MINGW64 /e/train/test1.0 (master)
$ git branch train        #新建train的支支
Administrator@Patrick MINGW64 /e/train/test1.0 (master)
$ git branch              #查看分支狀態,現在已經有兩個分支了,當前分支仍然是master
* master
  train

9、切換當前分支git checkout

Administrator@Patrick MINGW64 /e/train/test1.0 (master)
$ git checkout train             #切換到train分支
Switched to branch 'train'
Administrator@Patrick MINGW64 /e/train/test1.0 (train)
$ git branch                  #查看分支,train已經變成了當前分支
  master
*  train

10、遠程倉庫配置:git remote add git_path

$  git remote add ssh://****.****.com/train.git

11、查看遠程倉庫信息 git remote -v

$ git remote -v
origin   ssh://*****.com/train.git

原創文章,作者:N21-沉舟,如若轉載,請注明出處:http://www.www58058.com/21166

(0)
N21-沉舟N21-沉舟
上一篇 2016-07-04
下一篇 2016-07-04

相關推薦

  • 遷移用戶數據到獨立分區

    Linux操作系統中,/home目錄下為各個普通用戶的家目錄,主要用于存放用戶的配置信息及相關文件。若安裝操作系統時,采用了home目錄與根目錄處在同一分區的分區策略,那么隨著用戶數據較多,很有可能將分區空間耗盡,導致系統崩潰。所以最好是將用戶數據所在目錄放在一個獨立的分區上,但由于/home目錄下已有一些用戶數據,要想將home目錄建立在一個獨立的分區上,…

    Linux干貨 2017-08-13
  • lamp安裝配置詳細過程(把以前的筆記貼上來)

    準備; 首先進入/usr/local/目錄 #cd /usr/local 刪除所有安裝過的php mysql apache 以及libxml 首先查看目前 /usr/local目錄下面的內容 #ls –l 如果看到php5 php apache2 apache mysql mysql5 libxml libxml2字樣的目錄都將其刪除具體命令如下 #rm –…

    Linux干貨 2015-05-01
  • linux磁盤管理之LVM

                        LVM  LVM是 Logical Volume Manager(邏輯卷管理)的簡寫,它是Linux環境下對磁…

    Linux干貨 2016-09-09
  • DNS域名解析系統搭建(BIND)

        【本文導航】    零、準備工作    一、根域服務器配置    二、com頂級域配置    三、linux.com域主服務器配置(DNS1)    四…

    Linux干貨 2016-12-21
  • 馬哥教育網絡21期+第五周練習博客

    1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行; [root@localhost ~]#  grep '[^[:space:]]\+' /boot/grub2/grub.cfg 2、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符…

    Linux干貨 2016-08-08
  • 8月3日課堂練習及課后作業

    課堂練習 1、創建用戶gentoo,附加組為bin和root,默認shell為/bin/csh,注釋信息為“Gentoo Distribution” useradd -G bin,root -s /bin/csh -c "Gentoo Distribution" gentoo  2、創建下面的用戶、組和組成員關系,名字為admi…

    Linux干貨 2016-08-04
欧美性久久久久