第一步、在github上创建一个仓库
第二步、进入本地仓库/项目里,执行 git init 命令,这会多出.git文件夹。
第三步、为了把本地的仓库传到github,还需要配置ssh key。
命令:ssh-keygen -t rsa -C "your_email@youremail.com"
第四步、然后我们进入提示的地址下查看ssh key文件。 我的电脑的地址是c/Users/Administrator/.ssh/id_rsa.pub,把里面的内容添加到ssh key里面
保存后,验证是否成功,在git bash下输入:ssh -T git@github.com
输入yes回车就会看到:You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
第五步、接下来我们要做的就是把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们
$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"
第六步、进入本地仓库(文件夹),右键git bash,添加远程地址
$ git remote add origin 远程仓库地址
第七步、最后,提交代码,上传
命令:git add . 其中 . 代表所有文件
命令:git commit -m "注释内容"
命令:git push origin master
第一次上传代码,初始化项目,所以需要创建新分支 master,否则会报错。