共 个步骤
--1 在GitHub上创建仓库
--2 Git与GitHub之间通过SSH传输,因而要在本地生成一个私钥和密钥。
--方法: --- Git Bash下输入
命令行ssh-keygen -t rsa -C "你的邮箱"
--- 一直按空格下去最后会c:/用户/“用户名” 目录下生成.ssh目录,里面存放着的id_rsa.pub和id_rsa文件
---- 打开id_rsa.pub文件复制里面内容,在Github的用户setting页面左侧找到SSH keys项,粘贴进Key项,title名字起自己喜欢的,点击Add key按钮完成公钥的生成。
--3 到本地项目的目录下Git Bash。
--- 分五步输入下列command即可:
git init
git add README.md
git commit -m "描述这次提交的信息"
git remote add origin git@github.com:Github的用户名/仓库名
(如果仓库已经存在了的话用如下命令行)
git remote add origin
https://github.com/Github的用户名/仓库名.git
git push -u origin master
git push -u origin master
--- 期间可能出现的问题:
----Q1:执行git add README.md时出现fatal: pathspec 'README' did not match any files
原因:该命令是将文件加至暂存区域,表示该文件找不到,即是在目录里面不存在,创建好文件再添加。
----Q2:执行第4条命令行时报错“
fatal: remote origin already exists.
”
解决:先输入git remote rm origin后重新输入一次即可。
----Q3:执行git push -u origin master时报错信息如
“ ! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:levyc/SpringAccessDB.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远程仓库发生了变化,但是本地没有fetch(抓取)新变化下来就push到远程仓库。只要先执行git pull --rebase origin master获取最新改动即可解决。
----Q4:push成功后但是Github上没有本地项目的文件。
原因:没有将项目里面的文件添加进去就commit(提交)了。用git add . 将目录内所有文件添加进暂存区域再提交即可。