top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

Switching between local Git branches

0 votes
22 views

I've a question regarding the use of multiple local branches.

Let's say, I've created a branch b1 and made some changes like adding a new file to the branch b1 after checking it out. Then , I stage the file but not commit it.

Now I find myself a need to create another branch to work on a high severity issue. So, I checkout local master branch and create another b2 from master.

Now when I switch to b2, git shows the new file which is added to branch b1. Should not it replace the contents of my working directory with the contents of parent branch master? Instead it shows the new file when i do git status.

Please explain how does this work ?

posted Jul 4, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

0 votes

1) stage the file but not commit it.

2) Here is where you should 'stash' your changes. This is a special type of commit that you can get back later. Or you could just do a quick "WIP" commit of your changes.

3) What were the specific commands you used? Git tries to avoid deleting data so new files are in some cases left alone rather than overwriting them (which would be a Bad Thing)

answer Jul 4, 2013 by anonymous
0 votes

Im new to Git, so I might be wrong, but it sounds like you might want to use "stash" in this instance.
http://git-scm.com/book/en/Git-Tools-Stashing

answer Jul 4, 2013 by anonymous
Similar Questions
0 votes

I need to provide a list of all branches I have merged into develop since a given date.
Can you recommend a git command that will do this?

+1 vote

I have a large Git project which I would like to dissect into subprojects with their own repositories. Git subtrees are ideal for this task: I first

  • create a branch with the contents of only one subfoldergit subtree split -P -b

and then

  • pull this branch into another repository.

For a transitional phase, I would like to have the subprojects read-only and sync them from master. The question is how to organize this. For every commit to master, I could of course perform the above procedure repeatedly for all subprojects, but this seems less then ideal since it does all the work all over again.

Is there a way to merge master into the subtree branches?

+2 votes

One practice of using git to have one feature per branch.

Let's say a developer has worked on many small features in many branches. Then he sends one pull request to the central (not controlled by him) for each feature he has developed. While he is waiting for all the features be merged into the central repository, he needs to use all these feature locally.

To do so, he may need to merge the changes in these branches to his local master branch. But this can be tedious when he has many branches.

Is there a way to somehow setup a branch so whenever something is committed to the branch, the changes will also be simultaneously committed to the local master branch? By this way, the develop can avoid having to merge changes from many branches.

+2 votes

I tend to accumulate lots of branches as I'd do one branch per feature. When cleaning up, I'd like to
delete all branches, which have been merged.

I could use

 $ git branch -d (which was merged already?) ^C
 $ git branch --merged # let's find out
 ...
 $ # Now run git branch -d with each of the branches.

This kind of question has already been discussed,
http://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-are-already-merged
suggests: git branch --merged | grep -v "*" | xargs -n 1 git branch -d

I could think of:

 $ git branch -d --merged # no need to specifiy a branch iff --merged is given with -d
 $ git branch --delete-merged # comes as an new extra option, doesn't clutter other commands
 $ git branch -d keyword-for-all-merged-branches

Before starting such a feature, I'd like to hear input of others.


Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...