Git Bash上传文件
今天通过Git Bash上传了一个项目(之前是通过Github Desk上传的),操作命令如下:
在目录下shift+右键打开Git Bash
1.git init
2.git add *.py
3.git commit -m 'first'
4.然后在Github上新建一个仓库add repository,输入仓库名和描述
5.远程关联仓库,git remote add origin git@github.com:hyqyoung(用户名)/yylc_jdpm(仓库名).git
6.开始上传文件git push -u origin master
如果第六步遇到问题:
fatal: 'orign' does not appear to be a git repository
fatal: Could not read from remote repository.
则先删除关联:git remote rm origin
然后再执行第五、六步,要注意的是这里命令不要用上下键去调用,可能不会更新原来的操作,需要手敲
2018.5.4
今天在上传代码过程中,最后一步push的时候报了如下错误:
To github.com:hyqyoung/yylc_jdpm.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:hyqyoung/yylc_jdpm.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
原因是之前在GitHub的仓库里新建了一个README的文件,没有pull到本地。
所以在Github的远程仓库里做了一些变化的话,要及时pull到本地,代码:
git pull origin master
然后再进行1到6的步骤上传代码就可以了,
但是我原来做了一步不恰当的操作,那就是
git push -u origin master -f
强制执行,导致原来的远程仓库里的东西全部被替换掉了,所以切记这种操作是不可取的,并且尽量在本地做出一些修改,然后再push到GitHub上