Git

设置账号和用户名

# 查看git config设置
git config -l
git config --global user.name "xxx"
git config --global user.email "xxx"

Github / Gitee添加密钥

# 生成密钥
ssh-keygen -t rsa
# 查看公钥
cat ~/.ssh/id_rsa.pub

将公钥添加到Github / Gitee

添加多个远程仓库

  1. 将主库git到本地

    # 添加gitee库,使用ssh链接以防git push总是需要密码
    git remote add <远程库名> <ssh>
    # 查看远程仓库地址
    git remote -v
    
  2. push

    git push && git push <远程库名>
    
  3. 副库出现冲突

    hint: Updates were rejected because the tip of your current branch is behind
    
  4. 强行推送到副库

    # git push -u <远程库名> <版本名> -f
    git push -u gitee master -f
    

加速Git

  1. 安装nslookup

    sudo yum install bind-utils
    
  2. 查找DNS

    nslookup github.com
    nslookup github.global.ssl.fastly.net
    
  3. 修改hosts

  4. 刷新缓存

    • ubuntu

      sudo /etc/init.d/networking restart
      
    • mac

      sudo dscacheutil -flushcache
      
    • windows

      ipconfig /flushdns
      

拉取项目,修改代码后创建新版本

  1. 拉取已经fork远程项目

    git clone 远程项目
    
  2. 修改项目文件

  3. 创建版本分支

    git branch test
    
  4. 切换到版本分支

    git checkout test
    
  5. 提交文件

    git commit -m "test"
    
  6. 同步到远程分支版本

    git push origin test
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。