前提:先有一个GitHub账户,并创建好一个Github仓库,且本地成功安装git,如果没有请自行百度
开始
- 首先新建你的工程目录,比如D:\project,并进入,在空白处右键选择Git bash,通过命令行来创建
- 输入git init
把这个文件夹初始化git可管理的本地仓库,此时该目录下出现.git文件夹(默认隐藏) - 把代码粘进来,输入git add .
添加所有代码到本地仓库 - 输入 git commit -m “add new”
提交所有代码到本地仓库
此时暂停:
本地Git仓库和Github仓库传输通过SSH加密,需要创建SSH KEY
1.先检查本机用户目录下是否存在.ssh目录,里面是否有id_rsa、id_rsa.pub,如果有则跳过第2步
2.输入ssh-****** -t rsa -C “[email protected]”(提供你自己的邮箱),直接回车,根据提示输入密码和确认密码,最后生成id_rsa、id_rsa.pub文件
3.在GitHub上添加公钥
右上角点击
点击下面的按钮,新建一个SSH Key
配置SSH Key暂停继续,回到你的git bash窗口
- 输入git remote add origin [your url]
[your url]:你自己的仓库地址,如果不知道,从下图的地方copy
如果操作中提示 fatal: remote origin already exists.
使用 git remote rm origin
再重新git remote add origin 一下
- 输入git push origin master,开始上传。如果GitHub上的仓库是空的 需加-u 参数(git push -u origin master)
如果报
! [rejected] master -> master (fetch first)
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 pull --rebase origin master 同步一下,重新push
如果出现
error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
执行git config http.sslVerify “false”,如果又报git config http.sslVerify “false” fatal: not in a git directory
再继续执行git config --globle http.sslVerify “false”
- 任何操作过程中,都可以使用git status查看状态
- git remote -v
查看远程仓库 - git branch --set-upstream-to=origin/<远程分支名称> <本地分支名称>
关联远程仓库分支与本地分支