Let's suppose you have already registered on Github, and your login profile is as below:
username: spider-man
password: 123
Click this button to create a new repository:
Suppose you named your repository as angel。What you would see is like:
Please refer to the following link for more instructions and toturials:
http://git-scm.com/about
Go to http://git-scm.com/downloads, to download the GUI program on the client side for Windows.
Install it, continue the installation with the default configurations. No need to change anything.
Now create a new path on your local disc: D:\github/,and then put your files into that folder.
Run Git GUI which you just installed. Choose“创建新的版本库”, locate the path you just created in the window brought up, namely: "D:\github\". And then choose 'Repository'->'Git Bash' in the window that follows。
This brings up a command line window, with the path being the current execution path:
Most of the rest steps are according to this video tutorial: https://www.youtube.com/watch?v=GCBROgPCox0, and I actually don't understand all the underlying mechanism, because this is the first time I use github, it seems complicated.
First of all, the command that was executed in the tutorial was:
$ git init
Actually you can skip this step, since the GUI tool has already done it for us.
The next up is to run:
$ git add .
这个指令将刚刚你放进在本地github文件夹下的所有文件都添加到本地的版本库中。
然后执行:
$ git commit -m 'I hope this will work'
这个指令将提交添加的文件到库中,为它们创建本地的索引和快照等等,但并未提交到任何服务器上。m参数是必须填的,意思是附加信息,这些信息之后会被显示在上传文件和文件夹的备注上面。
现在执行:
$ git remote add origin https://github.com/spider-man/angel.git
其中最后的URL路径可以从该repository的页面获得。这个动作做的事情是将本地与这个网上的repository关联起来。
下面执行(在这个过程中你会需要用到用户名和密码):
$ git push -u origin master
实际上我在这里遇到麻烦了,并不像教程教的那样顺利:
()
提示中说另外一个上传推送的操作也在执行,建议我先更新同步,然后再执行上传。我想这是因为创建这个repository的时候我的一些设定导致一些默认文件被自动创建,而这些文件并没有没同步到我本地。
所以,我尝试执行了(在这个过程中你会需要用到用户名和密码):
$ git pull https://github.com/spider-man/angel.git
而这个指令执行的很顺利,那么我便继续执行了:
$ git push -u origin master
现在去刷新repository的页面:
所以正确的顺序应该是:
$ git add .
$ git commit -m '2006.11.10'
$ git pull https://github.com/spider-man/angel.git
$ git remote add origin https://github.com/spider-man/angel.git
$ git push -u origin master
如果是在针对同一个版本库,修改不同的版本并上传,那么后续的操作为:
$ git add .
$ git commit -m '2006.11.10'
$ git push -u origin master
而如果你不小心在设定remote origin的URL的时候弄错了,你发现想重新执行add origin指令或者移除这个origin已经不可能,这时候你可以执行:
$ git remote set-url origin https:github.com/righturl/
如果是对于同一工作路径有所修改后提交修改,需要注意,add . 这个指令并不追踪移除文件这类操作。所以如果你在项目中删去了一些无用的文件,那么这些删除操作不会被提交,在以后的版本中你一直都会发现这些文件,这时候你需要执行:
$ git add -u
http://stackoverflow.com/questions/1402776/how-do-i-commit-all-deleted-files-in-git
http://stackoverflow.com/questions/16807584/shortcut-for-git-add-ignore-removal
http://stackoverflow.com/questions/492558/removing-multiple-files-from-a-git-repo-that-have-already-been-deleted-from-disk
另外,如果在执行commit时打错了m参数后面的信息,可以执行这个指令修改:
$ git commit --amend
https://help.github.com/articles/can-i-delete-a-commit-message