【写成博客以便今后查阅】
1. 在github上注册帐号,创建一个repository (不需要勾选“Initialize this repository with a README”)。创建好了之后,会得到一个url例如https://github.com/username/repositoryname.git
2. 在本地机器上,找到想要上传的代码,进入根目录。(这里要求在本地安装Git工具,可以在这里下载Git)。安装之后,打开Git bush,在代码的根目录里执行
git init
来初始化本地文件夹,执行成功之后会在根目录创建一个隐藏文件夹“.git”,表示这个文件夹是一个repository,但是目前是空的。
3. 在Git bush中,执行以下命令,向空的repository中添加代码
git add .
其中的'.' 表示当前文件夹中所有的文件以及文件夹。
4. 然后执行
git commit -m 'some message'
向空的repository提交代码。
5. 向远程的repository添加一个origin
git remote add origin https://github.com/username/repositoryname.git
其中的url就是在第一步得到的url。
6. 将本地代码push到repository的origin的master分支中:
git push origin master
在执行命令的时候会提示你输入用户名和密码,然后将本地代码上传到github上。最后在你的github的repository中就可以看到代码了。