1、git有apt和source安装两种方式
1.1 apt安装
$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt-get update
$ sudo apt-get install git
1.2. source安装
安装git所依赖的文件
$ sudo apt-get install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
下载并解压源码 (https://git-scm.com/downloads)
cd到git目录下,编译源码
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install
两种方式安装git之后可以用
$ git --version 查看版本
2. git的使用
2.1 git配置
初始化版本库
git init
指定用户名和邮箱
$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@domain.com"
可以查看配置信息(两种方式都可以):
$ cat ~/.gitconfig
$ git config --list
2.2 git操作
git remote add [origin] [url] #要添加一个新的远程仓库
git add 文件 #将文件添加到暂存区
git clone http://github.com/schacon/ticgit.git #某个项目远程git仓库的地址
git commit -m "readme.txt提交" #把文件提交到仓库
git config --list #看所有用户
git status #查看git状态
git push [remote-name] [branch-name] #推送项目到远程分支
3.遇到的问题
To github.com:fyyzkd/DNN.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:fyyzkd/DNN.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
出现错误的主要原因:
github中的README.md文件不在本地代码目录中
解决方案:
$ git pull --rebase origin master
$ git push -u origin master