git 本地分支与远程分支 - 图1

查看本地分支和远程分支

  1. git branch -vv
  2. git remote show origin
  3. cat .git/config
  4. git branch -a

本地分支与远程分支进行关联

分两种情况:

  1. 本地创建了分支dev,而远程没有
    1. git push -u origin dev 或
    2. git push —set-upstream-to=origin/dev dev
  2. 远程创建了分支dev,而本地没有
    1. git pull origin dev // 先将远程分支dev pull到本地
    2. git checkout -b dev origin/dev

把上面的命令合在一起,可以写成下面格式
git pull origin dev:dev

image.png

查看本地分支对应的远程分支

git branch -va
git branch -vv

Git global settings

  1. git config --global user.name "hnscdg"
  2. git config --global user.email "hnscdg@126.com"

Create git repository

  1. mkdir data-screen
  2. cd data-screen
  3. git init
  4. touch README.md
  5. git add README.md
  6. git commit -m "first commit"
  7. git remote add origin https://gitee.com/hnscdg/data-screen.git
  8. git push -u origin master

Existing repository

  1. cd existing_git_repo
  2. git remote add origin https://gitee.com/hnscdg/data-screen.git
  3. git push -u origin master