# git fetch,git merge and git rebase

11 messages from 2011-02-10 to 2011-02-11. Participants: Akash, Alexey Shumkin, Jonathan Nieder, Neal Kreitzinger, Jeff King, Felipe Contreras.
Thread: https://gitlist.dev/t/26460

## Akash, 2011-02-10 05:29

Subject: git fetch,git merge and git rebase
Message-ID: <1297315789338-6010561.post@n2.nabble.com>
URL: https://gitlist.dev/e/1297315789338-6010561.post%40n2.nabble.com

```

Hi,

I am new to git .Can someone explain in simple terms what git fetch,git
merge and git rebase do?..I tried googling but was very confused after going
thro it.

Also, can someone prescribe a link which explains git in detail right from
scratch.


-- 
View this message in context: http://git.661346.n2.nabble.com/git-fetch-git-merge-and-git-rebase-tp6010561p6010561.html
Sent from the git mailing list archive at Nabble.com.

```

## Alexey Shumkin, 2011-02-10 07:22

Subject: Re: git fetch,git merge and git rebase
Message-ID: <loom.20110210T082201-996@post.gmane.org>
URL: https://gitlist.dev/e/loom.20110210T082201-996%40post.gmane.org
In-Reply-To: <1297315789338-6010561.post@n2.nabble.com>

```
Akash <bcakashguru <at> gmail.com> writes:

> 
> 
> Hi,
> 
> I am new to git .Can someone explain in simple terms what git fetch,git
> merge and git rebase do?..I tried googling but was very confused after going
> thro it.
> 
> Also, can someone prescribe a link which explains git in detail right from
> scratch.
> 

RFTM, with all respect ))
http://progit.org/book/

```

## Alexey Shumkin, 2011-02-10 07:25

Subject: Re: git fetch,git merge and git rebase
Message-ID: <loom.20110210T082411-967@post.gmane.org>
URL: https://gitlist.dev/e/loom.20110210T082411-967%40post.gmane.org
In-Reply-To: <1297315789338-6010561.post@n2.nabble.com>

```
> I am new to git .Can someone explain in simple terms what git fetch,git
> merge and git rebase do?..I tried googling but was very confused after going
> thro it.

and also https://git.wiki.kernel.org/index.php/GitFaq

```

## Jonathan Nieder, 2011-02-10 08:22

Subject: Re: git fetch,git merge and git rebase
Message-ID: <20110210082218.GA5997@elie>
URL: https://gitlist.dev/e/20110210082218.GA5997%40elie
In-Reply-To: <loom.20110210T082201-996@post.gmane.org>

```
Alexey Shumkin wrote:
> Akash writes:

>> I am new to git .Can someone explain in simple terms what git fetch,git
>> merge and git rebase do?..I tried googling but was very confused after going
>> thro it.
>> 
>> Also, can someone prescribe a link which explains git in detail right from
>> scratch.
>
> RFTM, with all respect ))
> http://progit.org/book/

More hints:

 - "man git" (or "git help git") has some hints to get started:
   . a tutorial
   . a list of "everyday git" commands to get going
   . a short article on centralized, cvs-style workflow
   . a user's manual

 - when anything is unclear in those documents, I will be very happy
   to learn about it (so cc me in that case :)).  Please be specific
   as possible about what is confusing.

 - people on this mailing list and the #git channel on freenode are
   generally happy to help if you are trying to do something
   specific (or have some other specific question).

 - there's much material on the web in addition to what's mentioned
   above.  For example the old git crash course for svn users at
   http://git.or.cz/course/svn.html taught me a lot about both git and
   svn.  Theoretically, good material from a variety of sources can
   gradually flow into the user's manual and reference manual pages,
   though actual practice does not always match that theory.

Good luck.

Kind regards,
Jonathan

```

## Neal Kreitzinger, 2011-02-10 20:00

Subject: Re: git fetch,git merge and git rebase
Message-ID: <4D5443D1.9000904@gmail.com>
URL: https://gitlist.dev/e/4D5443D1.9000904%40gmail.com
In-Reply-To: <1297315789338-6010561.post@n2.nabble.com>

```
On 2/9/2011 11:29 PM, Akash wrote:
>
> Hi,
>
> I am new to git .Can someone explain in simple terms what git fetch,git
> merge and git rebase do?..I tried googling but was very confused after going
> thro it.
>
> Also, can someone prescribe a link which explains git in detail right from
> scratch.
>
>
git fetch:  retrieve the latest version of a branch and store it in the 
/remotes/* "remote tracking branches" of your local repo.  you can view 
these branches with "git branch -a".  Once you have that local copy, you 
can merge it into other branches, checkout objects from it, and run 
diffs against it.  You are not supposed to EVER make commits on a 
remote/* branch.  its sole purpose in life is to maintain an image the 
the corresponding branchs that its tracking in the remote repo.  you 
update that image by performing git fetch.  see man-page for details.

git merge:  merges branch(s) into your current branch.  see man-page for 
details.  lots and lots of details...

git rebase:  takes all the local commits you've made on an old history 
and rewrites them on-top of the new history.  it makes it look like you 
did your work based on the new history instead of the old history.  it 
keeps your history 'linear' instead of having all these merge DAG's in 
your history like git-merge produces.  see man page for details.  lots 
and lots of details are not easy to understand at first...

hope this helps.

v/r,
neal

```

## Neal Kreitzinger, 2011-02-10 22:21

Subject: Re: git fetch,git merge and git rebase
Message-ID: <4D5464E7.2010407@gmail.com>
URL: https://gitlist.dev/e/4D5464E7.2010407%40gmail.com
In-Reply-To: <1297315789338-6010561.post@n2.nabble.com>

```
On 2/9/2011 11:29 PM, Akash wrote:
>
> Hi,
>
> I am new to git .Can someone explain in simple terms what git fetch,git
> merge and git rebase do?..I tried googling but was very confused after going
> thro it.
>
> Also, can someone prescribe a link which explains git in detail right from
> scratch.
>
>
another definition of git-rebase:

git-rebase:  the MOST DANGEROUS command in git.  you can easily DESTROY 
your repo if you don't know what you're doing!  Until you get the hang 
of it, always make a copy of the before-image of the branch your 
rebasing (mybranch) by doing a "git checkout mybranch" and then "git 
branch copy-of-mybranch".  Then if you destroy mybranch you can recover 
it from copy-of-mybranch.

v/r,
neal

```

## Jeff King, 2011-02-10 23:03

Subject: Re: git fetch,git merge and git rebase
Message-ID: <20110210230337.GB21335@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20110210230337.GB21335%40sigill.intra.peff.net
In-Reply-To: <4D5464E7.2010407@gmail.com>

```
On Thu, Feb 10, 2011 at 04:21:27PM -0600, Neal Kreitzinger wrote:

> another definition of git-rebase:
> 
> git-rebase:  the MOST DANGEROUS command in git.  you can easily
> DESTROY your repo if you don't know what you're doing!  Until you get
> the hang of it, always make a copy of the before-image of the branch
> your rebasing (mybranch) by doing a "git checkout mybranch" and then
> "git branch copy-of-mybranch".  Then if you destroy mybranch you can
> recover it from copy-of-mybranch.

I won't claim that rebase isn't easy to shoot yourself in the foot with,
but I think this advice is a little over-the-top. Rather than backing up
branches, you would do better to learn about reflogs, as the reflog of
mybranch will contain the original version. As will the reflog of HEAD,
though if you have screwed up too badly, the reflog of mybranch will
probably be a lot simpler to read.

You can see it with "git reflog show mybranch"; when you see the commit
that you want to restore to, you can:

  git branch -f mybranch mybranch@{whatever}

to restore it there. That provides more-or-less the same safety as a
backup branch (reflogs do expire, but something like three months
later), plus it helps you in all the cases where you forgot to make a
backup before screwing things up. :)

-Peff

```

## Akash, 2011-02-11 06:59

Subject: Re: git fetch,git merge and git rebase
Message-ID: <1297407554244-6014719.post@n2.nabble.com>
URL: https://gitlist.dev/e/1297407554244-6014719.post%40n2.nabble.com
In-Reply-To: <20110210082218.GA5997@elie>

```

Thanks Jonathan:)
-- 
View this message in context: http://git.661346.n2.nabble.com/git-fetch-git-merge-and-git-rebase-tp6010561p6014719.html
Sent from the git mailing list archive at Nabble.com.

```

## Akash, 2011-02-11 07:00

Subject: Re: git fetch,git merge and git rebase
Message-ID: <1297407623396-6014723.post@n2.nabble.com>
URL: https://gitlist.dev/e/1297407623396-6014723.post%40n2.nabble.com
In-Reply-To: <20110210230337.GB21335@sigill.intra.peff.net>

```

Thanks Neal:)
-- 
View this message in context: http://git.661346.n2.nabble.com/git-fetch-git-merge-and-git-rebase-tp6010561p6014723.html
Sent from the git mailing list archive at Nabble.com.

```

## Felipe Contreras, 2011-02-11 12:32

Subject: Re: git fetch,git merge and git rebase
Message-ID: <AANLkTinsBz0Yi5XXYUcaJMTvkjuhtNjotx0VWRFcKX3d@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinsBz0Yi5XXYUcaJMTvkjuhtNjotx0VWRFcKX3d%40mail.gmail.com
In-Reply-To: <4D5464E7.2010407@gmail.com>

```
On Fri, Feb 11, 2011 at 12:21 AM, Neal Kreitzinger
<nkreitzinger@gmail.com> wrote:
> On 2/9/2011 11:29 PM, Akash wrote:
>>
>> Hi,
>>
>> I am new to git .Can someone explain in simple terms what git fetch,git
>> merge and git rebase do?..I tried googling but was very confused after
>> going
>> thro it.
>>
>> Also, can someone prescribe a link which explains git in detail right from
>> scratch.
>>
>>
> another definition of git-rebase:
>
> git-rebase:  the MOST DANGEROUS command in git.  you can easily DESTROY your
> repo if you don't know what you're doing!  Until you get the hang of it,
> always make a copy of the before-image of the branch your rebasing
> (mybranch) by doing a "git checkout mybranch" and then "git branch
> copy-of-mybranch".  Then if you destroy mybranch you can recover it from
> copy-of-mybranch.

What about 'git rebase --hard', or 'git branch -D'? In all cases you
can recover by using the reflog.

-- 
Felipe Contreras

```

## Neal Kreitzinger, 2011-02-11 17:13

Subject: Re: git fetch,git merge and git rebase
Message-ID: <4D556E56.30702@gmail.com>
URL: https://gitlist.dev/e/4D556E56.30702%40gmail.com
In-Reply-To: <AANLkTinsBz0Yi5XXYUcaJMTvkjuhtNjotx0VWRFcKX3d@mail.gmail.com>

```
On 2/11/2011 6:32 AM, Felipe Contreras wrote:
> On Fri, Feb 11, 2011 at 12:21 AM, Neal Kreitzinger
> <nkreitzinger@gmail.com>  wrote:
>> On 2/9/2011 11:29 PM, Akash wrote:
>>> Hi,
>>>
>>> I am new to git .Can someone explain in simple terms what git fetch,git
>>> merge and git rebase do?..I tried googling but was very confused after
>>> going
>>> thro it.
>>>
>>> Also, can someone prescribe a link which explains git in detail right from
>>> scratch.
>>>
>>>
>> another definition of git-rebase:
>>
>> git-rebase:  the MOST DANGEROUS command in git.  you can easily DESTROY your
>> repo if you don't know what you're doing!  Until you get the hang of it,
>> always make a copy of the before-image of the branch your rebasing
>> (mybranch) by doing a "git checkout mybranch" and then "git branch
>> copy-of-mybranch".  Then if you destroy mybranch you can recover it from
>> copy-of-mybranch.
> What about 'git rebase --hard', or 'git branch -D'? In all cases you
> can recover by using the reflog.
>
i take you meant 'git reset --hard'...

v/r,
neal

```
