Git使用之开发者

近年来Git的热度居高不下,本文是笔者对Git的一些常用命令做的记录。

初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
git init
# 初始化本地仓库

git remote add <remote> <url>
# 添加远程版本库,remote可自行取名,默认origin,url为远程仓库的HTTPS或者SSH地址

git remote -v
# 查看远程版本库信息

git remote remove <remote>
# 删除远程remote链接

git pull <remote> <branch>
# 下载代码及快速合并 remote为添加的版本库别名,branch可以是dev:master(dev为远端分支,master为本地分支)

image

代码拉取和推送

  • 每天开发之前需要先拉取一遍远程版本库的代码

    1
    2
    3
    4
    5
    git fetch <remote> <branch>
    # 将远端库获取到本地但不合并,remote为添加的版本库别名,branch为远端的分支名

    git merge <branch>
    # 将获取的远端分支合并到本地目前所在的分支

    image

  • 每天开发完成后进行代码提交(需要再次进行线上的拉取)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    git add .
    # 添加所有改动到缓存区

    git commit -m '描述'
    # 提交缓存区内的文件,并提供描述

    git status
    # 查看当前版本状态(是否clean)

    git fetch <remote> <branch>
    # 将远端库获取到本地但不合并,remote为添加的版本库别名,branch为远端的分支名

    git merge <branch>
    # 将获取的远端分支合并到本地目前所在的分支

    git push <remote> <branch>
    # 上传代码及快速合并,remote为添加的版本库别名,branch可以是master:dev(master为本地分支,dev为远端分支)

    image

0%