Ubuntu 中git的安装与使用

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值