Ubuntu下git使用教程
2016-01-01 08:24
239 查看
安装git
sudo apt-get install git
检查SSH
GitHub用到了SSH,需要在shell里检查是否连接到GitHub:willard@willard-PC~/github/blog $ ssh -T git@github.com Hi willard-yuan! You've successfully authenticated, but GitHub does not provide shell access.
上面表明添加成功。
克隆rep
比较常见的将远程版本库中的代码clone到本地的方式如下:git clone git@github.com:willard-yuan/blog.git
其他常用Git命令
git init # 初始化本地Git版本库 git add # 暂存文件,如果使用.表示当前目录及其子目录 git commit -m “first commit” # 提交,-m选项后跟内容为提交所用的注释 git remote -v # 查看当前项目远程连接的是哪个版本库地址 git push origin master # 将本地项目提交到远程版本库 git fetch origin # 取得远程更新(到origin/master),但还没有合并 git merge origin/master # 把更新的内容(origin/master)合并到本地分支(master) git pull origin master # 相当于fetch和merge的合并,但分步操作更保险 git branch -r #查看分支 git checkout origin/master(gh-pages) #切换分支 git push origin :branch_you_want_to_delete #删除远程分支(注意空格,把一个空的branch赋值给已有的branch,这样就删除了)
示例
willard@willard-PC~/github $ git clone git@github.com:willard-yuan/pcvwithpython.git Cloning into 'pcvwithpython'... remote: Reusing existing pack: 1960, done. remote: Total 1960 (delta 0), reused 0 (delta 0) Receiving objects: 100% (1960/1960), 58.58 MiB | 2.10 MiB/s, done. Resolving deltas: 100% (671/671), done. Checking connectivity... done.
克隆下来后,便可以对项目的文件进行修改添加,修改添加完成后,提交到远程版本控制库:
willard@willard-PC~/github/pcvwithpython $ git add . willard@willard-PC~/github/pcvwithpython $ git commit -m "update content in ch07"[gh-pages 221c8bc] update content in ch07 1 file changed, 4 insertions(+)
在push之前,我们先来查看一下当前项目远程连接的是哪个版本库地址:
willard@willard-PC~/github/pcvwithpython $ git remote -v origin git@github.com:willard-yuan/pcvwithpython.git (fetch) origin git@github.com:willard-yuan/pcvwithpython.git (push)
然后push:
git push
注意,这里本小子并没有用
git push origin master,用该命令,出现下面错误:
willard@willard-PC~/github/pcvwithpython $ git push origin master Warning: Permanently added the RSA host key for IP address '2001:778:0:ffff:64:0:c01e:fc83' to the list of known hosts. error: src refspec master does not match any. error: failed to push some refs to 'git@github.com:willard-yuan/pcvwithpython.git
暂时就这样吧。
Reference:
[1].Ubuntu下GitHub的使用
[2].在Ubuntu下配置舒服的Python开发环境
from: http://yongyuan.name/blog/the-trick-of-using-git.html
相关文章推荐
- Ubuntu 默认壁纸历代记
- Ubuntu Remix Cinnamon 20.04 评测:Ubuntu 与 Cinnamon 的完美融合
- 关于Ubuntu 11.10启动提示waiting for the network configuration的问题
- 在 Ubuntu 桌面中使用文件和文件夹
- RPC failed; result=22, HTTP code = 411
- git更新已經刪除的文件
- ubuntu下chrome无法同步问题解决
- Ubuntu Linux使用体验
- 使用 GNOME 优化工具自定义 Linux 桌面的 10 种方法
- 以Ubuntu 9.04为例 将工作环境迁移到 Linux
- 提取Git每次提交后Commit的文件
- GIT迁移服务器
- VirtualBox虚拟机XP与宿主机Ubuntu互访共享文件夹
- 从USB安装Ubuntu Server 10.04.3 图文详解
- Ubuntu 15.04 正式版发布下载
- Linux-Ubuntu 10.04安装Cadence-ic610 方法总结图解
- Ubuntu 12.04和Windows 7双系统安装图解
- 开机出现:grub rescue的修复方法
- Ubuntu连接Android真机调试
- 分布式版本管理git入门指南使用资料汇总及文章推荐