Reputation: 5955
I follow this git workflow
I clone the project in the folder myproject and checkout the develop branch:
git clone the_remote_url myproject git checkout develop
I received a task in this morning, so I create a branch from develop to implement this task:
git checkout -b task1 develop
To implement the task1, I need to add some other files into my project, and modify some files. In the afternoon, my team leader asked me to do the task2, because the task2 is more urgent. So in the folder "myproject", I create another branch "task2" from develop, and switch from task1 to task2.
git checkout -b task2 develop
What I expected is when I am on the task2 branch, all files I created on task1 branch must be disappeared. However, they are still there.
What is the best practice to implement several tasks (on different branches) in the same folder (myproject) ?
Upvotes: 0
Views: 69
Reputation: 17455
Check this tutorial, it begins from simple use-cases.
Basically before switching to a new branch you should examine your work tree for uncommitted changes and commit them first. Use git add with subsequent git commit. You also may find git add --interactive
, git commit --all
and git stash
useful (or use GUI tools like git gui
).
Upvotes: 1