创建一个新的repository:
先在github上创建并写好相关名字,描述。(github的创建,可以参考这里https://help.github.com/articles/create-a-repo)
如果我们创建了hello-world,那么下面的操作如下:
1 | $cd ~/hello-world //到hello-world目录 |
更新项目(新加了文件):
1 | $cd ~/hello-world |
更新项目(没新加文件,只有删除或者修改文件):
1 | $cd ~/hello-world |
忽略一些文件,比如*.o等:
1 | $cd ~/hello-world |
然后就可以git add . 能自动过滤这种文件
clone代码到本地:
1 | $git clone [email protected]:zhangda89/hello-world.git //假如本地已经存在了代码,而仓库里有更新,把更改的合并到本地的项目: |
撤销
1 | $git reset |
删除
1 | $git rm * // 不是用rm |
常见错误
git remote add origin [email protected]:zhangda89/hello-world.git
错误提示:fatal: remote origin already exists.
解决办法: $git remote rm origin
然后在执行:$git remote add origin [email protected]:zhangda89/hello-world.git
就不会报错误了
git push origin master
错误提示:error:failed to push som refs to
解决办法: $git pull origin master
//先把远程服务器github上面的文件拉先来,再push 上去。