threads / discuss / 24737

Basic Git usage

Subject: Basic Git usage

## tl;dr

3 messages between Aug 14, 2010 and Aug 14, 2010.

replies: 2people: 3as markdown or json

hogsolo· Aug 14, 2010, 04:32 UTC · lore

Hi, Im new to Git, formerly an SVN user. I have a master repo and have created a branch. I want to work in both at the same time. I want to change some files in the master, then switch to the branch ( git checkout branchname) , work on some files, then switch back to the master. However git wont let me switch back to the master until I have added, committed and pushed my files in the branch. Is this correct behavior for git? It would seem that I not be REQUIRED to check in anything I was working on before switching between branch and master, but that's the behavior I'm seeing via error messages.

thanks
-- 
View this message in context: http://git.661346.n2.nabble.com/Basic-Git-usage-tp5422412p5422412.html
Sent from the git mailing list archive at Nabble.com.
Jakub Narebski· Aug 14, 2010, 12:39 UTC · re: hogsolo · lore

Re: Basic Git usage

hogsolo <greg@localdirt.com> writes:
Show 13 quoted lines
> Hi, Im new to Git, formerly an SVN user.
>
> I have a master repo and have created a branch. I want to work in both at
> the same time. I want to change some files in the master, then switch to the
> branch ( git checkout branchname) , work on some files, then switch back to
> the master. 
>
> However git wont let me switch back to the master until I have added,
> committed and pushed my files in the branch. 
>
> Is this correct behavior for git? It would seem that I not be REQUIRED to
> check in anything I was working on before switching between branch and
> master, but that's the behavior I'm seeing via error messages.

Git wouldn't allow you to switch a branch ('git checkout <branch>') if you have uncomitted changes that would conflict with the branch you switch to. For example if you have uncomitted changes to file 'foo', and this file is different on the branch you switch to, then git rightly refuses to switch branches.

You can tell git to try to merge changes with
  git checkout -m <branch>
or you can force git to discard your local changes with
  git checkout -f <branch>
or you can stash away your changes before switching branch.
In no case _pushing_ changes is a requirement.
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Dmitry Potapov· Aug 14, 2010, 19:41 UTC · re: hogsolo · lore

Re: Basic Git usage

On Sat, Aug 14, 2010 at 8:32 AM, hogsolo <greg@localdirt.com> wrote:
Show 7 quoted lines
>
> I have a master repo and have created a branch. I want to work in both at
> the same time. I want to change some files in the master, then switch to the
> branch ( git checkout branchname) , work on some files, then switch back to
> the master.
> However git wont let me switch back to the master until I have added,
> committed and pushed my files in the branch.
If you have modified files that are different between two branches then
Git won't allow to switch between them. You have two options:
- to commit your changes
- use "git stash"

In contrast to SVN and some other VCS, Git allows you to amend any commit later. To amend the last commit on the current branch, 'git commit --amend' can be used. If you want to modify arbitrary commits, (or squash, or delete some commits) take a look at: "git rebase --interactive"

Warning: modifying commits that you published (i.e. made available to
other users) is in general a bad idea, because it makes difficult for
other users to work with you.
Dmitry

← back to recent threads