5分钟发布项目到github

git bash提交本地项目到远程仓库

1、cd进入你放项目文件的地址

2、输入git init

如下图所示,这个意思是在当前项目的目录中生成本地的git管理(会发现在当前目录下多了一个.git文件夹)

3、输入git add .

这个是将项目上所有的文件添加到仓库中的意思,如果想添加某个特定的文件,只需把.换成这个特定的文件名及其.后缀即可。

4、输入git commit -m "first commit",表示你对这次提交的注释,双引号里面的内容可以根据个人的需要修改。

5、输入git remote add origin https://自己的仓库url地址,将本地的仓库关联到github上

这里出现报错

先输入$ git remote rm origin,再输入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不会报错了!

6、输入git push -u origin master,这是把代码上传到github仓库的意思。

执行完后,如果没有异常,会等待几秒会跳出一个让你输入Username和Password 的窗口,你只要输人github的登录账号和密码就OK。

7、在使用git 对源代码进行push到gitHub时可能会出错,信息如下

主要原因是github中的README.md文件不在本地代码目录中,或者本地仓库中的内容不全

可以通过如下命令进行代码合并【注:pull=fetch+merge]

git pull --rebase origin master

执行上面代码后可以看到本地代码库中多了README.md文件

此时再执行语句 git push -u origin master即可完成代码上传到github

有可能出现以下错误问题:使用git push -u 远程库名 master 命令将本地提交的内容传到git远程库时出现错误:

命令: git push -u origin master

出现错误:
  To https://github.com/imjinghun/university.git
  ! [rejected] master -> master (fetch first)
  error: failed to push some refs to 'https://github.com/imjinghun/university.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.

解决:使用 git push -f 命令重新传一遍就可以成功了

命令:git push -f

8、也有可能出现以下错误

git 执行git pull –rebase报错误如下:

error: Cannot pull with rebase: You have unstaged changes.
error: Additionally, your index contains uncommitted changes.

原因:如果有未提交的更改,是不能git pull的

解决:

先执行git stash
再执行git pull –rebase
最后再执行git stash pop

git stash (用来暂存当前正在进行的工作)
git stash pop (从Git栈中读取最近一次保存的内容)

原文地址:https://www.cnblogs.com/hackerZT-7/p/12475130.html