• git常用操作


    1  查看状态  

    nicknailodeMacBook-Pro:mmall nicknailo$ git init
    nicknailodeMacBook-Pro:mmall nicknailo$ git status

    2 添加文件到本地仓库

     git add .
     git commit -am 'first commit init project'

    3 向git仓库提交代码

    git remote add origin 远程地址
    

      此时发生了报错, Permission denied (publickey),进入~/.ssh/id_rsa.pub,把公钥复制到远程地址的公钥设置上。

      如果报错caused by another repository pushing,先  git pull  后 git push 

    4 提交代码

    git push -u origin master
    

     这里可能会报错 the tip of your current branch is behind,因为刚才推送的还没覆盖之前的版本,再使用命令 git push -u -f origin master,-f代表强制推送

    5 查看分支

    nicknailodeMacBook-Pro:mmall nicknailo$ git branch
    * master
    nicknailodeMacBook-Pro:mmall nicknailo$ git branch -r
      origin/master
    

    6 添加分支  v1.0

    git checkout -b v1.0 origin/master
    

    7 向远程推送分支

    git push origin HEAD -u
    

     远程的分支建立好了。

    8 向远程分支传代码

      git push <远程主机名> <本地分支名>:<远程分支名>

      如果 <远程分支名>和<本地分支名> 名字一样,可以只写一个

    注意,分支推送顺序的写法是<来源地>:<目的地>,所以git pull是<远程分支>:<本地分支>,而git push是<本地分支>:<远程分支>。
    git push origin xf:xf

     9 从远程分支上拉取代码

    git pull <远程库名> <远程分支名>:<本地分支名>

      比如,取回远程库中的online分支,与本地的online分支进行merge,要写成:

      如果 <远程分支名>和<本地分支名> 名字一样,可以只写一个

    git pull origin online:online
  • 相关阅读:
    构建之法阅读笔记2
    2020.2.10
    2020.2.9
    2020.2.8
    2020.2.7
    2020.2.6
    2020.2.5
    学习进度——第十三周
    PHPStorm+XAMPP开发php项目
    第一阶段成果建议
  • 原文地址:https://www.cnblogs.com/nicknailo/p/8613259.html
Copyright © 2020-2023  润新知