Basic Git usage
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
Signature · 2 lines
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.
Quoted 7 lines · hogsolo
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
Quoted 7 lines · hogsolo
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.
Quoted 6 lines
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.
Signature · 3 lines
Jakub Narebski Poland ShadeHawk on #git