将本地代码备份到Github public repository

1. 在本地代码所在的文件夹中初始化,即打开powershell,输入下面命令

git init

此时本地文件夹中会出现一个`.git`的隐藏文件夹。

 

2. 然后将当前的文档`commit`,在本地`commit`之前可以先加一个`.gitignore`文件,忽略一些不必要的文件,如VS的编译文件等等,从其他仓库拷贝一个放在里面就行(需要添加过滤)。然后执行命令

git status
git add *
git commit -m "first commit"

 

3. 然后登陆自己的GitHub账户,在右上角调集`+`号新建一个新的仓库,取个名字如 MyRepository。

 

4. 再回到本地,再powershell中键入

git remote add origin https://github.com/YourGithubName/MyRepository.git    
git push -u origin master

 

OK!

原文地址:https://www.cnblogs.com/VVingerfly/p/8215493.html