Terry Martin
Terry Martin

Reputation: 579

Git checkout branch doesn't change working directory

I am not exactly sure how to phrase this question, as I am new to git. One of my coworkers was working on a feature in a branch called "rotation." I wanted to make use of the code he wrote, so I ran git checkout rotation. The main difference between master and rotation branches is that the rotation branch has an extra subdirectory titled rotation/. However, after running git checkout, this subdirectory did not show up in my working directory. How do I get this subdirectory to show up? I did some googling and found that git doesn't make changes to your working directory when you git checkout a branch if those changes would conflict with tracked changes in your working directory. However, this is not the case here, at least for the rotation/ subdirectory, as it does not even exist in master. So why doesn't this subdirectory show up? How do I get it to?

Upvotes: 4

Views: 8168

Answers (3)

Code-Apprentice
Code-Apprentice

Reputation: 83587

In the following comments, I assume that there are three repositories, your own local repo, your coworker's repo, and a central repo. It sounds like you already have a local branch named rotation. If your coworker pushed her rotation branch to the central repo, you need to update that branch with your coworker's changes:

$ git checkout rotation
$ git pull origin rotation

Note, that if your coworker only created a directory without adding any files, then she cannot commit it. Git does not track directories themselves. Instead, it tracks files and stores extra information about the directory where the file belongs.

Upvotes: 3

sunw
sunw

Reputation: 643

Simply checking out the branch isn't enough to get remote changes to your machine. You must use git pull or git fetch.

Here is a useful diagram you can use as a reference.

Upvotes: 7

Nacev
Nacev

Reputation: 154

Have you tried git pull origin rotation? The form should be git pull <remote> <branchname>.

Upvotes: 4

Related Questions