git 添加本地文件夹到远程仓库

依次执行:

git init

git add .

git commit -m "init"

git remote add origin https://github.com/leohe666/grpc-helloworld.git

git push -u origin master

 

最后命令的- u 是 --set-upstream 的简写,它的主要作用是 建立本地分支与远程分支的追踪关系

核心作用详解:

  1. 建立关联关系

    • 执行后会记录:当前本地分支 默认推送到 远程仓库/分支 的对应关系

    • 信息保存在 .git/config 文件中

  2. 后续操作简化

    # 首次推送(建立关联)
    git push -u origin master
    
    # 之后只需要(自动知道推送到origin/master)
    git push  
    git pull
  3. 分支状态可视化

    • 使用 git branch -vv 可以看到:

      * master 1a2b3c4 [origin/master] 最新提交信息