根据实际需要,需要将本地的项目放到github上;
首先在本地已有的项目下,用git bash命令进入,然后执行:ssh-keygen -t rsa -C "你的远程git邮箱地址";
执行完之后找到C:/User/用户名/.ssh/文件夹,其中有两个文件,一个是id_rsa是私钥,id_rsa.pub是公钥,复制公钥里面的内容,到github上找到setting,中的ssh……Key,然后将复制的内容考进去,生成对应的SSH Key即可;
此时已经可以与github进行ssh通信了;
在本地仓库执行:
git init // 通过命令 git init 把这个目录变成git可以管理的仓库
git add . // 把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数
// 点“.”,意为添加文件夹下的所有文件(夹)。
git commit -m "first commit" // commit到本地仓库
git remote add origin "远程仓库的地址" // 与远程仓库进行关联
git push -u origin master // 将本地仓库的内容push 到远程仓库
注:1.如果在进行关联远程仓库的时候,提示:
Permission denied (publickey)
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
说明很有可能就是你没有配置ssh权限,需要进行配置ssh权限:ssh-keygen -t C rsa "你的邮箱地址";然后按照之前的步骤一步步配置SSH key;
2. 在关联远程仓库的时候提示:fatal: remote origin already exists.
需要删除远程的仓库,然后再执行相同的关联语句;
git remote rm origin;
参考:https://blog.csdn.net/top_code/article/details/50381432