# Git branch with same content

**URL:** <https://www.ruby-forum.com/t/git-branch-with-same-content/163024>\
**Category:** Rails\
**Created:** [March 16, 2009, 8:06pm UTC](https://www.ruby-forum.com/t/git-branch-with-same-content/163024 "2009-03-16T20:06:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [March 16, 2009, 8:06pm UTC](https://www.ruby-forum.com/t/git-branch-with-same-content/163024/1 "2009-03-16T20:06:59Z")

</div>

I’m rather new to Git and trying to learn it.

I did a new branch. I switched over to the new branch by checkout. I  
added some files and some code, directly in Textmate. But when I  
switched back to my master branch the same new files are there too.  
Isn’t that wrong?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [March 16, 2009, 8:35pm UTC](https://www.ruby-forum.com/t/git-branch-with-same-content/163024/2 "2009-03-16T20:35:43Z")

</div>

Did you remember to commit the new files before switching back to  
master?

2009/3/16 PÃ¥l BergstrÃ¶m [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [March 16, 2009, 8:56pm UTC](https://www.ruby-forum.com/t/git-branch-with-same-content/163024/3 "2009-03-16T20:56:54Z")

</div>

On 03/16/2009 04:34 PM, Colin L. wrote:

> Did you remember to commit the new files before switching back to master?

What if I can’t/don’t want to commit now? Should I stage my files?

Thanks,

davi

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [March 16, 2009, 9:08pm UTC](https://www.ruby-forum.com/t/git-branch-with-same-content/163024/4 "2009-03-16T21:08:03Z")

</div>

Git has a magic command ‘git stash’ that saves any uncommitted (no  
need to  
stage them) files without actually committing them. You can then switch  
to a  
different branch, or do anything else you like. When you are ready to  
carry  
on go back to the branch (actually it doesn’t have to be the same branch  
if  
you realised you were working on the wrong one) and use ‘git stash  
apply’ to  
get your work back.

2009/3/16 Davi V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [March 16, 2009, 10:38pm UTC](https://www.ruby-forum.com/t/git-branch-with-same-content/163024/5 "2009-03-16T22:38:50Z")

</div>

Colin L. wrote:

> Did you remember to commit the new files before switching back to  
> master?
> 
> 2009/3/16 PÃ¥l BergstrÃ¶m [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Yes I did. I used \> git commit -a -v -m “message”

Then I did a checkout in order to returning to master branch.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [March 16, 2009, 9:11pm UTC](https://www.ruby-forum.com/t/git-branch-with-same-content/163024/6 "2009-03-16T21:11:01Z")

</div>

I’m not sure if you will be able to switch to old branch if you add  
new files to index, but if you cannot commit files you can use git  
stash. On the other hand you can commit them although you didn’t  
finish complete development since that commit will not disturb  
anything until you publish your changes with git push. After you  
finish development and perform series of commits to new branch you can  
squash your commits into single commit and that’s it. So there is no  
reason not to commit new files on the development branch.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [March 16, 2009, 11:06pm UTC](https://www.ruby-forum.com/t/git-branch-with-same-content/163024/7 "2009-03-16T23:06:17Z")

</div>

PÃ¥l BergstrÃ¶m wrote:

> Yes I did. I used \> git commit -a -v -m “message”
> 
> Then I did a checkout in order to returning to master branch.

Sorry. Seems to work now. My bad. Must have been the cache function of  
the server, which is a bit problematic in LiteSpeed Web Server (but  
otherwise a great server).

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [March 17, 2009, 4:27am UTC](https://www.ruby-forum.com/t/git-branch-with-same-content/163024/8 "2009-03-17T04:27:36Z")

</div>

On 03/16/2009 05:10 PM, Bosko I. wrote:

> (…) On the other hand you can commit them (…) since that commit will  
> not disturb anything until you publish your changes with git push.  
> (…)  
> (…) So there is no reason not to commit new files on the development branch.

Yeah. I know. 🙂  
Just a simple doubt that occurred to me. 🙂

But thank you very much, Colin and Bosko.

davi
