把本地项目提交到 github 上

    xiaoxiao2021-04-15  41

    本地项目提交到github

    下列的操作,我假装你已经安装和配置好了本地git

    1.到本地项目的目录,输入命令行:

    git init //初始化本地,会生成.git文件

    2.把项目添加到本地仓库(myApp)

    git add . //添加所有文件 git add readme.md //只添加文件readme

    3.提交并添加本地仓库

    git commit -m '这是我提交的文件'

    4.在自己的github上面新建仓库(repository),并命名为myApp(与本地项目同名),然后拷贝项目地址:https://github.com/zchuhui/myApp.git

    5.把本地仓库的项目提交到github上面

    //添加远程地址 git remote add myapp https://github.com/zchuhui/myApp.git //推送主分支(master)到github上去 git push -u myapp master //或 //强行推送当前分支到远程仓库,即使有冲突 $ git push [remote] --force

    6.大功告成,赶快去查看你的github吧


    常见操作错误:

    remote add 时经常会报错:==fatal: remote origin already exists.==

    解决方案:输入 ==$ git remote rm origin== 再 remote add 就行了


    从github上面获取项目

    1.直接克隆github上的项目

    git clone https://github.com/zchuhui/myapp.git

    2.取回远程仓库的变化,并与本地分支合并

    git remote add myapp https://github.com/zchuhui/myApp.git git pull myapp

    在github新建新分支

    前提:该项目已经提交到github的master分支上

    1.在本地新建一个分支:

    git branch Branch1

    2.切换到你的新分支:

    git checkout Branch1

    3.将新分支发布在github上:

    git push origin Branch1

    然后,在github上项目页面设置: setting > Branches > Default branch上查看默认分支。

    即可看到新建的分支:Branch1

    转载请注明原文地址: https://ju.6miu.com/read-671183.html

    最新回复(0)