详细文档可以参考廖雪峰git教程 网址http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
下面记录一些常见操作
本地仓库与远程仓库关联
git remote add origin git@github.com:michaelliao/learngit.git
注意把用户名换成自己的
git add "filename"
git commit -m "提交说明"
git push origin master 意思是提交到远程库master分支
遇到类似与下面的错误
[rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.oschina.net/sulliy/i.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
可以通过命令 git pull origin master 解决 用来同步远程和本地
如果git pull origin master 报错:refuse to merge unrelated histories
可以用 git pull --allow-unrelated-histories origin master 即可强行合并
下面介绍最想记录的一点 删除远程库文件,即删除远程githup网站上的文件
使用 git rm 命令即可,有两种选择.
一种是 git rm --cached "文件路径",不删除物理文件,仅将该文件从缓存中删除;
一种是 git rm --f "文件路径",不仅将该文件从缓存中删除,还会将物理文件删除(不会回收到垃圾桶)
假如你有文件不小心commit到了服务器那么你想要删除它,可以使用:
- git rm -- cached "路径+文件名"
接下来:
- git commit -m "delete file"
最后:
- git push origin master