初学者~

有两篇吧,一篇在github上  https://github.com/DefaultYuan/Git-Pro/wiki/Introduction

文章来源:《git的简单使用》http://www.jianshu.com/p/4105f1f21490(下面是此链接的直接copy)

之前用svn的,但是愕然发现好多公司都开始用git ,一开始不知道为什么,想想那么多公司用它,肯定有它的优点啥,带着好奇的心态,慢慢开始去研究它,由于我们公司,就我一个iOS,所以暂时好多git的好多优点都是持续发掘的,本文也会持续更新中····

一、安装

我们用的都是Mac,所以可以直接通过homebrew安装Git,具体方法请参考homebrew的文档:http://brew.sh/

 $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

然后再检查

 $ git version // 判断是否安装成功,查看版本号

然后,设置你的个人信息

 $ git config --global user.name "YourName"
$ git config --global user.email "YourEmail"

注意'git config'命令的'--global'参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。

二、基本使用

2-1、可以新建一个文件夹,mkdir testGit, 然后cd testGit

 $ git init  // 创建仓库
Initialized empty Git repository in /Users/testGit/.git/

2-2、增加你需要改变的东西,放到testGit中去,添加到仓库中去

 $ git add .  // 注意 . 是增加所有的

2-3、提交到仓库中去 -m “这里面是需要注释的内容”

 $ git commit -m "first init "

2-4、接下来就是看,你的远程仓库建在什么地方啦,我在github 和 coding 上都有,个人认为刚开始在coding 上使用还是不错的

 $ git remote add origin git@coding.com....

假如此时遇到这个问题,fatal: Authentication failed for,那么有可能是没有添加ssh key导致的,具体可以参考这文章git ssh key 的生成

2-5、把内容推送到远程库上

  $ git push -u origin master //由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令
$ git push origin master // 后期,当然在分支的情况,另论

2-6、然后每次用之前

 $ git pull origin master // 每次使用之前最好刷新一下

实际上现在到目前为止就可以开始用起来啦,当然分支管理这个大部分我们后期在讨论。
常用的命令

 $ git status   // 查看每次变化的
$ git log // 查看每次记录的
$ git log --pretty=oneline // 查看记录更清晰 $ git clone git@github.com:****.git // 从远程仓库克隆,常用

2-7、建立分支并切换

  $ git  branch  分支名字  // 建立分支
$ git checkout 分支名字 // 切换到分支 $ git branch // 查看分支

2-8、合并分支

  //先切换主支
$ git checkout master
$ git merge --no-ff 分支名字

三、理解

工作区-----仓库----远程仓库(git add; git commit ; git push )

屏幕快照 2015-10-09 上午11.30.31.png

屏幕快照 2015-10-09 上午11.30.43.png

四、常见问题(陆续增加中···)

4-1(问)、合并的时候遇到的冲突

error: There was a problem with the editor 'vi'.
Not committing merge; use 'git commit' to complete the merge.
E325: ATTENTION
Found a swap file by the name ".git/.MERGE_MSG.swp"
owned by: eladb dated: Tue Aug 20 10:52:03 2013
file name: ~eladb/MyWorkspace/Client/.git/MERGE_MSG
modified: no
user name: eladb host name: Elads-MacBook-Pro-2.local
process ID: 29959 (still running)
While opening file ".git/MERGE_MSG"
dated: Tue Aug 20 10:53:11 2013
NEWER than swap file!
(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r .git/MERGE_MSG"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".git/.MERGE_MSG.swp"
to avoid this message.
Swap file ".git/.MERGE_MSG.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)born:

4-1(答)解决方法:

找到".git/.MERGE_MSG.swp",之后删除即可,然后重新git add .;
git commit -m "";git push master 之后,再执行 git merge branchName 就好啦

4-2 git push 出现的警告问题

warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior,use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

解决:

git config --global push.default matching或者git config --global push.default simple命令,以后再push就不会有警告了。
下面说一下push.default matching和push.default simple的区别:
push.default设置maching的意思是:git push 会把你本地所有分支push到名称相对应的远程主机上。这意味着可能你会在不经意间push一些你原本没打算push的分支。
push.default设置成simple的意思是:git push仅仅把当前所在分支push到从当初git pull pull下来的那个对应分支上,另外,这个过程也会同时检查各个分支的名称是否相对应。

平常最好用 $ git push origin BRANCH #BRANCH是你远程分支的名字

相应的 git pull

  git pull origin BRANCH #BRANCH是你远程分支的名字
4-3 git merge 合并时遇到的冲突, Automatic merge failed; fix conflicts and then commit the result
$ git merge secondDev
Auto-merging myTest.txt
CONFLICT (content): Merge conflict in myTest.txt
Automatic merge failed; fix conflicts and then commit the result.

自动合并失败。由于在同一行进行了修改,所以产生了冲突。

在冲突处

add 把变更录入到索引中
commit 记录索引的状态
pull 取得远端数据库的内容

然后重新提交

$ git add myTest.txt
$ git commit -m "合并secondDev分支"
# On branch master
nothing to commit (working directory clean)

五、一张很好用git 的图

git 图
参考链接(安装中配置和使用的基本)

1、http://blog.csdn.net/matrixhero/article/details/8214156
// 基本的安装及配置
2、http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137396287703354d8c6c01c904c7d9ff056ae23da865a000 // 详细的讲解和说明,

初始github——git的简单使用的更多相关文章

  1. Linux下的GitHub安装与简单配置教程 ~ 转载

    Linux下的GitHub安装与简单配置教程   1.GitHub简介 Git是一个分布式版本控制系统,与其相对的是CVS.SVN等集中式的版本控制系统. 2.Git的安装 1)安装Git a.查看与 ...

  2. linux下git的简单运用

    linux下git的简单运用 windows下也有git,是git公司出的bash,基本上模拟了linux下命令行.许多常用的命令和linux下操作一样.也就是说,windows下的git命令操作和l ...

  3. Linux下的GitHub安装与简单配置教程

    1.GitHub简介 Git是一个分布式版本控制系统,与其相对的是CVS.SVN等集中式的版本控制系统. 2.Git的安装 1)安装Git a.查看与使用 在ubuntu下可以使用如下命令进行查看系统 ...

  4. GitBook是一个命令行工具(Node.js库),我们可以借用该工具使用Github/Git和Markdown来制作精美的图书,但它并不是一本关于Git的教程哟。

    GitBook是一个命令行工具(Node.js库),我们可以借用该工具使用Github/Git和Markdown来制作精美的图书,但它并不是一本关于Git的教程哟. 支持输出多种格式 GitBook支 ...

  5. eclipse IDE使用git方法简单介绍

    eclipse下使用git插件上传代码至github 1.eclipse下安装git eclipse  git 插件的安装. 点击 Help->Install New Software-> ...

  6. (转)初学Git及简单搭建git服务器和客户端

    终于搞定,mac自己作为git服务器,mac也是客户端,如何免登 从另外一个linux服务器的上传公钥得到提示 ssh-copy-id -i ~/.ssh/id_rsa.pub git@192.168 ...

  7. Git 命令简单罗列

    源教程出自 廖雪峰的官方网站 https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 整 ...

  8. 【转载】手把手教你使用Git(简单,实用)

    手把手教你使用Git(简单,实用) 标签: git 2016年04月21日 20:51:45 1328人阅读 评论(0) 收藏 举报 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. ...

  9. git的简单使用方式(基本操作部分)

    git的简单使用方式(基本操作部分) 1.简单介绍GIT的工作流程 git一般的工作流程: 克隆git的资源作为工作目录(一般会使用命令git clone进行克隆); 在克隆的资源上对文件进行增加或者 ...

随机推荐

  1. [洛谷P3195][HNOI2008]玩具装箱TOY

    题目大意:有n个物体,大小为$c_i$.把第i个到第j个放到一起,容器的长度为$x=j-i+\sum\limits_{k-i}^{j} c_k$,若长度为x,费用为$(x-L)^2$.费用最小. 题解 ...

  2. [Leetcode] Reverse linked list ii 反转链表

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given1->2 ...

  3. 【BZOJ 1724】[Usaco2006 Nov]Fence Repair 切割木板 堆+贪心

    堆对于stl priority_queue ,我们自己定义的类自己重载<,对于非自定义类我们默认大根堆,如若改成小根堆则写成std::priority<int,vector<int& ...

  4. POJ3349 Snowflake Snow Snowflakes (hash

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 48624   Accep ...

  5. AngularJS+BootStrap的一些插件

    插件网址:http://jquerypluginplus.com/ 树  1.angular-bootstrap-nav-tree http://jquerypluginplus.com/angula ...

  6. lesson 4 再谈继承多态,抽象类和接口

    再谈多态,抽象类和接口 上一次博客已经概念性的概述了继承多态,抽象类和接口,这次来具体的谈一谈他们之间的联系和需要注意的地方. 一.继承和多态:Inheritance (继承) & Polym ...

  7. shell正则表达式(1)

    一.什么是正则 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则. 二.grep 1.参数 -n  :显示行号 -o  : ...

  8. bzoj1420/1319 Discrete Root

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1420 http://www.lydsy.com/JudgeOnline/problem.ph ...

  9. float/文档流

    float : left | right | none | inherit; 文档流是文档中可显示对象在排列时所占用的位置. 浮动的定义: 使元素脱离文档流,按照指定方向发生移动,遇到父级边界或者相邻 ...

  10. 【洛谷 P2515】 [HAOI2010]软件安装 (缩点+树形背包)

    题目链接 看到代价和价值这两个关键词,肯定是首先要想到背包的. 但是图中并没有说这是棵树,所以先要\(Tarjan\)缩点,然后就是选课了,跑一遍树形背包就好了. 注意:缩点后应该是一个森林,应该用一 ...