Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics (2015) Getting Started with Express Your First Express App

Steven Quinn
Steven Quinn
12,519 Points

Cannot run git checkout

I can't run git checkout yourFirstExpressApp. I get the following error: The following untracked working tree files would be overwritten by checkout: .gitignore package.json Please move or remove them before you can switch branches. Aborting

Can anybody tell me what I've done wrong here?

2 Answers

Samuel Webb
Samuel Webb
25,370 Points

It's because you're trying to switch branches while you have changed, unsaved files that are already being tracked by Git. Which would be .gitignore and package.json. Your options are to:

  1. Save the files before doing your git checkout

  2. Put them back into their original state, save them, git checkout

I am having the same issue, but I don't understand this answer.

In my case, the files haven't been edited, so there's nothing to save. And putting the files back into their original state sounds like it means to undo everything that was done in the previous lesson. Terminal says to move or remove them before using checkout.

Sean Pascoe
Sean Pascoe
17,151 Points

I think by "save" he means "commit". Git is just trying to prevent you from losing any changes you have made to your repository. Make a quick commit and after that you should be able to checkout another branch.

git commit -a -m 'wow great changes'

EDIT: Found the answer :) I need to do git add -A before committing the changes!

Hello Sean Pascoe! I'm having the same issue as Allison. I tried running your command and I get the following:

On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
../.DS_Store
../.gitignore
../package.json
./
nothing added to commit but untracked files present

Then, when I try to re-run git checkout yourFirstExpressApp I get the same issue again. Any idea what that could be? Thanks!