# How to create & switch to a branch after changes have already been made?

4 messages from 2007-07-03 to 2007-07-03. Participants: Patrick Doyle, Johannes Schindelin.
Thread: https://gitlist.dev/t/8824

## Patrick Doyle, 2007-07-03 02:18

Subject: How to create & switch to a branch after changes have already been made?
Message-ID: <e2a1d0aa0707021918mb335856j278b3128203a793a@mail.gmail.com>
URL: https://gitlist.dev/e/e2a1d0aa0707021918mb335856j278b3128203a793a%40mail.gmail.com

```
Suppose, hypothetically speaking, one were a long time user of CVS who
converted to subversion in the last 18 months or so, and who never
really understood branches and merging because the syntax was so
obtuse and because the projects this hypothetical person had worked
were short lived enough that (s)he never really needed to create a
branch.

Now suppose this hypothetical person was working on a new project,
decided to use git as the project's version control system, got
halfway through changing a bunch of files, wanted to commit them as
they were, since they worked, but were ugly as sin, and wanted to
clean them up before committing them back to the main line of
development.

I would tell that hypothetical person, "Gee, it sounds like a branch
is exactly what you need here".  Unfortunately I don't know how to
tell the person to do the equivalent of a "svn switch" when the local
repository has been modified.

$ git branch newbranch
 that works, but
$ git checkout newbranch
complains that an untracked file would be overwritten by the merge
(since one of the things that this hypothetical person may have done
would have been to do a "git mv somefile someotherfile").

What would you suggest I say to this person other than "get in the
habit of creating a new branch _any_ time you start something new".

--wpd

```

## Patrick Doyle, 2007-07-03 02:49

Subject: Re: How to create & switch to a branch after changes have already been made?
Message-ID: <e2a1d0aa0707021949k181f9042j26ebd124f61ca1ae@mail.gmail.com>
URL: https://gitlist.dev/e/e2a1d0aa0707021949k181f9042j26ebd124f61ca1ae%40mail.gmail.com
In-Reply-To: <e2a1d0aa0707021918mb335856j278b3128203a793a@mail.gmail.com>

```
Hmmm...
One thing I might tell the hypothetical person is to temporarily
delete or rename the new version of "somefile", so that the merge
could complete with problems, and then recreate or rename it back.
That would probably allow the hypothetical person to continue his/her
work.

--wpd

```

## Johannes Schindelin, 2007-07-03 11:10

Subject: Re: How to create & switch to a branch after changes have already been made?
Message-ID: <Pine.LNX.4.64.0707031210020.4071@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0707031210020.4071%40racer.site
In-Reply-To: <e2a1d0aa0707021949k181f9042j26ebd124f61ca1ae@mail.gmail.com>

```
Hi,

On Mon, 2 Jul 2007, Patrick Doyle wrote:

> Hmmm... One thing I might tell the hypothetical person is to temporarily 
> delete or rename the new version of "somefile", so that the merge could 
> complete with problems, and then recreate or rename it back. That would 
> probably allow the hypothetical person to continue his/her work.

You could also say "git checkout -f newbranch".

Ciao,
Dscho

```

## Patrick Doyle, 2007-07-03 14:04

Subject: Re: How to create & switch to a branch after changes have already been made?
Message-ID: <e2a1d0aa0707030704r45769fdaw2413a4cad19be935@mail.gmail.com>
URL: https://gitlist.dev/e/e2a1d0aa0707030704r45769fdaw2413a4cad19be935%40mail.gmail.com
In-Reply-To: <Pine.LNX.4.64.0707031210020.4071@racer.site>

```
The real problem was that I did a

$ git-mv somefile somefile.new

and then created a new version of "somefile".  When I temporarily
renamed it, all of the given suggestions worked.  Thanks.

--wpd

```
