Git常用命令

  • 代码提交

    1
    2
    3
    4
    5
    6
    git init
    git add .
    git commit -m "first commit"
    # 关联远程仓库
    git remote add origin [https://github.com/xxxx/xxxx.git]
    git push -u origin [branchName]
  • config

    1
    2
    3
    4
    5
    6
    7
    # 非全局配置
    git config user.email "your-email-address"
    git config user.name "your-username"

    # 全局配置
    git config --global user.email "your-email-address"
    git config --global user.name "your-username"
  • 修改分支名称

    1
    git branch -m [source] [target]
  • 删除本地分支、远程分支

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # 查询所有分支
    git branch -a
    # 切换到其他分支
    git checkout [other_branch_name]

    # 删除本地分支,
    # -d 会检查分支状态
    # -D 大写为强制删除,不检查分支状态
    git branch -d [local_branch_name]

    # 删除远程分支
    git push origin -d [branch_name]