Git代理配置

  • http/https代理

    • 全局

      1
      2
      git config --global http.proxy http://127.0.0.1:7890
      git config --global https.proxy http://127.0.0.1:7890
    • 特定域名

      1
      2
      git config --global http.https://github.com.proxy http://127.0.0.1:7890
      git config --global https.https://github.com.proxy http://127.0.0.1:7890
    • 取消

      1
      2
      git config --global --unset http.proxy
      git config --global --unset http.https://github.com.proxy
  • SSH代理

    • nc:netcat

      1
      brew install netcat
    • 在/etc/ssh/ssh_config中加入如下:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      Host github.com
      User git
      Port 22
      Hostname github.com
      IdentityFile ~/.ssh/id_rsa
      TCPKeepAlive yes
      ProxyCommand /usr/bin/nc -x 127.0.0.1:7890 %h %p

      Host ssh.github.com
      User git
      Port 443
      Hostname ssh.github.com
      IdentityFile ~/.ssh/id_rsa
      TCPKeepAlive yes
      ProxyCommand /usr/bin/nc -x 127.0.0.1:7890 %h %p
  • 注意nc一定要用绝对路径

Git基本配置

  • 添加用户名

    1
    git config --global --add user.name <yourname>
  • 查看用户名

    1
    git config --global user.name <yourname>
  • 添加邮箱

    1
    git config --global --add user.email <youremail>
  • 查看用户名

    1
    git config --global user.email <yourname>

Github常用操作

连接远程仓库

1
git remote add origin git@github.com:lzh594/DBSEC2023-Lab3.git

为推送当前分支并建立与远程上游的跟踪

1
git push --set-upstream origin master

推送

1
git push -u origin

拉取

  • 更新某分支最新版本并合并至本地分支

1
2
git pull
git pull origin somebranch

分支

  • 创建并切换

    1
    git checkout -b newbranch
  • 切换到分支B

    1
    git switch B
  • 位于分支B,推送到远程分支B

    1
    2
    3
    git push
    // 第一次push可能需要跟踪远程上游
    git push --set-upstream origin B

合并

  • 位于某分支A,将B分支合并到A上

    1
    git merge B