本文记录了如何在windows下将本地项目同步到Github
创建Github账户
安装cmder
创建本地版本库
- 进入项目根目录
- 右键cmder here
- 在cmder中输入
git init来初始化本地仓库 - 在cmder中输入
git add .把该目录下所有文件添加到仓库 - 在cmder中输入
git commit -m "init commit"将项目提交到仓库
创建秘钥并关联远程仓库
- 在cmder中输入
git config --global user.name "username"和git config --global user.email your@email.com配置 - 在cmder中输入
ssh-keygen -t rsa -C "youremail@example.com"生成秘钥 - 在C:\Users\yourusername\.ssh在目录下找到id_rsa.pub文件,可以用记事本或者其他文本工具打开该文件并全选复制里面的公钥
- 登录Github找到Settings,找到其中SSH and GPG keys功能,New SSH key,其中的Title可以随便命名,然后将复制的公钥粘贴到Key中,最后点击Add SSH key
- 在Github上Create a new repository,Repository name与项目名相同,不选择创建README,点击Create repository
- 继续在cmder中输入以下命令关联远程仓库
git remote add origin https://github.com/username/repositoryname.git
将本地仓库内容推送到远程仓库
在cmder中输入git push -u origin master,由于新建的远程仓库是空的,所以要加上-u这个参数。在以后的使用中你可以只需要做以下的操作即可将本地内容同步到Github中
|
|