Ubuntu12.04下安装Git 以及常用命令
2014-04-18 16:36
573 查看
1. 安装 git
mark@M8V:~$ sudo apt-get install git
2. 创建github帐号。略。
3. 在Ubuntu上生成公钥。
ssh-keygen -C "jgcheng@github.com" -f ~/.ssh/github
4. 把第3步生成的github.pub公钥拷贝粘贴到github上自己帐号设置里的SSH key
5. 测试。
mark@M8V:~/.ssh$ssh -T git@github.com
返回:
Hi JGCheng! You've successfully authenticated, but GitHub does not provide shell access.
成功!
6. 设置个人信息
下面的名字应该是你真实的名字。而不是要GitHub的用户名。
mark@M8V:~/git/repos$ git config --global user.name "Mark Cheng"
mark@M8V:~/git/repos$ git config --global user.email "biosd_c AT qq.com"
7. 在github上创建一个repository
略
8. 加个文件到项目。
mkdir -p git/repos
cd git/repos
git init
touch .vimrc
git add .vimrc
git commit -m "Add .vimrc first time."
git remote add origin https://github.com/JGCheng/vimrc.git
// 第二次就可以不用执行这个了。
git push -u origin master
Git 常用命令
1.创建一个新的repository:
先在github上创建并写好相关名字,描述。
$cd ~/coredump
$git init //初始化
$git add . //把所有文件加入到索引(不想把所有文件加入,可以用gitignore或add 具体文件)
$git commit //提交到本地仓库,然后会填写更新日志( -m “更新日志”也可)
$git remote add origin https://github.com/JGCheng/coredump.git //增加到remote
$git push origin master //push到github上
2.更新项目(新加了文件):
$cd ~/coredump
$git add . //这样可以自动判断新加了哪些文件,或者手动加入文件名字
$git commit //提交到本地仓库
$git push origin master //不是新创建的,不用再add 到remote上了
3.更新项目(没新加文件,只有删除或者修改文件):
$cd ~/coredump
$git commit -a //记录删除或修改了哪些文件
$git push origin master //提交到github
4.忽略一些文件,比如*.o等:
$cd ~/coredump
$vim .gitignore //把文件类型加入到.gitignore中,保存
然后就可以git add . 能自动过滤这种文件
5.clone代码到本地:
$git clone https://github.com/JGCheng/coredump.git
假如本地已经存在了代码,而仓库里有更新,把更改的合并到本地的项目:
$git fetch origin //获取远程更新
$git merge origin/master //把更新的内容合并到本地分支
6.撤销
$git reset
7.删除
$git rm * // 不是用rm
错误:
1. 在执行
$ git remote add origin https://github.com/JGCheng/coredump-under-Linux.git 错误提示:fatal: remote origin already exists.
解决办法:
$ git remote rm origin
然后在执行:$ git remote add originhttps://github.com/JGCheng/coredump-under-Linux.git 就不会报错误了
2.
$ git push origin master
错误提示:error:failed to push som refs to.......
解决办法:
$ git pull origin master //先把远程服务器github上面的文件拉先来,再push 上去。
mark@M8V:~$ sudo apt-get install git
2. 创建github帐号。略。
3. 在Ubuntu上生成公钥。
ssh-keygen -C "jgcheng@github.com" -f ~/.ssh/github
4. 把第3步生成的github.pub公钥拷贝粘贴到github上自己帐号设置里的SSH key
5. 测试。
mark@M8V:~/.ssh$ssh -T git@github.com
返回:
Hi JGCheng! You've successfully authenticated, but GitHub does not provide shell access.
成功!
6. 设置个人信息
下面的名字应该是你真实的名字。而不是要GitHub的用户名。
mark@M8V:~/git/repos$ git config --global user.name "Mark Cheng"
mark@M8V:~/git/repos$ git config --global user.email "biosd_c AT qq.com"
7. 在github上创建一个repository
略
8. 加个文件到项目。
mkdir -p git/repos
cd git/repos
git init
touch .vimrc
git add .vimrc
git commit -m "Add .vimrc first time."
git remote add origin https://github.com/JGCheng/vimrc.git
// 第二次就可以不用执行这个了。
git push -u origin master
Git 常用命令
1.创建一个新的repository:
先在github上创建并写好相关名字,描述。
$cd ~/coredump
$git init //初始化
$git add . //把所有文件加入到索引(不想把所有文件加入,可以用gitignore或add 具体文件)
$git commit //提交到本地仓库,然后会填写更新日志( -m “更新日志”也可)
$git remote add origin https://github.com/JGCheng/coredump.git //增加到remote
$git push origin master //push到github上
2.更新项目(新加了文件):
$cd ~/coredump
$git add . //这样可以自动判断新加了哪些文件,或者手动加入文件名字
$git commit //提交到本地仓库
$git push origin master //不是新创建的,不用再add 到remote上了
3.更新项目(没新加文件,只有删除或者修改文件):
$cd ~/coredump
$git commit -a //记录删除或修改了哪些文件
$git push origin master //提交到github
4.忽略一些文件,比如*.o等:
$cd ~/coredump
$vim .gitignore //把文件类型加入到.gitignore中,保存
然后就可以git add . 能自动过滤这种文件
5.clone代码到本地:
$git clone https://github.com/JGCheng/coredump.git
假如本地已经存在了代码,而仓库里有更新,把更改的合并到本地的项目:
$git fetch origin //获取远程更新
$git merge origin/master //把更新的内容合并到本地分支
6.撤销
$git reset
7.删除
$git rm * // 不是用rm
错误:
1. 在执行
$ git remote add origin https://github.com/JGCheng/coredump-under-Linux.git 错误提示:fatal: remote origin already exists.
解决办法:
$ git remote rm origin
然后在执行:$ git remote add originhttps://github.com/JGCheng/coredump-under-Linux.git 就不会报错误了
2.
$ git push origin master
错误提示:error:failed to push som refs to.......
解决办法:
$ git pull origin master //先把远程服务器github上面的文件拉先来,再push 上去。
相关文章推荐
- Git快速入门——Git安装、创建版本库以及常用命令
- linux_安装git以及相关的常用命令整理
- git安装以及常用命令
- 安装node多版本管理器nvm,以及nvm常用命令
- git--版本工具的常用命令以及初始化实操
- Linux --- git的常用命令以及在github上获取,上传代码
- linux命令、软件的安装、卸载以及常用命令
- liunx的安装以及常用的命令操作
- git常用命令总结以及用github来展示你的前端页面
- CentOS 下安装7-Zip 以及常用的解压命令
- Xshell 和Xftp 得安装与使用以及常用得命令
- git 安装及常用命令
- git常用操作,以及常用命令 全
- GIT常用命令以及使用详解图示
- 在linux上安装JDK碰到的问题以及linux常用命令的学习
- git log常用命令以及技巧
- windows下安装git并创建一个仓库,git常用命令
- MAC端Git安装,命令使用以及环境搭建
- 分布式版本控制系统Git(三):git使用总结以及常用命令
- win10安装Git步骤和常用的Git命令