美文网首页
Mac环境 如何上传本地项目到GitHub

Mac环境 如何上传本地项目到GitHub

作者: 百事星空 | 来源:发表于2019-06-16 12:53 被阅读0次

    上传项目

    在github上新建一个空的项目,不需要ignore和readme文件
    把项目地址放到xcode > preferences > accounts里面
    执行以下步骤就可以把项目上传到github上啦

    cd XXX/XXX   (打开终端 进入项目的根目录 )
    git init  // 初始化git
    git add . // add所有文件
    git commit -m "first commit" // 提交到本地仓库
    git remote add origin https://github.com/yaoliangjun/Test.git // 项目地址
    git push -u origin master // 提交到远程库
    

    如果项目有其他人一起开发,在push代码之前需要pull一下最新的代码,命令如下:

    git pull origin master
    

    报错的处理:
    (1)
    升级MacOS Sierra到Mac Mojave后执行git命令报错:

    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    
    //解决方案:
    xcode-select --install
    

    (2)

    $ git push -u origin master
    To git@github.com:xxx/xxx.git
     ! [rejected]        master -> master (fetch first)
    error: failed to push some refs to 'git@github.com:xxx/xxx.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    
    原因: 
    GitHub远程仓库中的README.md文件不在本地仓库中。
    //解决方案:
    $ git pull --rebase origin master
    $ git push -u origin master
    

    参考:mac如何使用Git上传本地项目到github?
    Mac下使用git对GitHub进行推送,拉取等操作

    更新代码

    • 查看代码的修改
    git status 
    //modified 标示修改的文件 
    //deleted标示删除的文件 
    // untracked files 未处理的文件 需要执行 git add方法添加上去
    
    • 提交代码
    git commit -m "注释"   注意添加注释
    
    • 同步代码
    git pull origin master
    
    • 把代码推到服务器上
    git push origin master
    

    相关文章

      网友评论

          本文标题:Mac环境 如何上传本地项目到GitHub

          本文链接:https://www.haomeiwen.com/subject/tmwwfctx.html