0

I have a Github repository and I'm trying to pull the repository (it's already cloned) to my home machine but for some reason it does not pull all the folders from the Github repository.

I tried both the fetch and pull but the result is same.

When I do the pull, under Update result, I get a DIRTYTREE error on a .pyc file.

This is a simple python project.

and my github link is https://github.com/PREM1980/Test/tree/master/ecomstore/ecomstore/templates

and the folder I'm trying to retrieve is templates.

michaeltwofish
  • 4,096
  • 3
  • 28
  • 32
user1050619
  • 19,822
  • 85
  • 237
  • 413
  • This looks like a pretty good post regarding your issue: http://stackoverflow.com/questions/9855946/is-it-safe-to-git-pull-when-my-working-tree-and-or-index-is-dirty – sheldonk May 02 '13 at 00:27
  • Would you mind showing the complete error? – Cristian Eduardo Lehuede Lyon May 02 '13 at 00:27
  • That's not a question. – joshuahealy May 02 '13 at 00:27
  • First, the link you showed is not a repo, it's a directory in the middle of a repo. And there are no .pyc files inside that `templates` or its subdirectories. I'm willing to bet you're actually trying to pull the parent directory, and the error is one of those .pyc files checked in there, although of course it's hard to be sure with incomplete and incorrect information. – abarnert May 02 '13 at 00:40
  • yes, you are correct..ecomstore is the actual project I want to pull that project in the repository? Is it good to have one repository for one project?? – user1050619 May 02 '13 at 00:43
  • Yes, it is good to have one repo for one project. You can put multiple projects into a repo if you want—but if you pull the whole repo, get an error in project A, and ask people for help with project B, it's going to confuse people and delay getting you help… – abarnert May 02 '13 at 00:47
  • Thanks much..Let me create separate repos for projects..Thanks for below explanation as well. – user1050619 May 02 '13 at 01:19

1 Answers1

1

When I do the pull, under Update result, I get a DIRTYTREE error on a .pyc file..

There are no .pyc files under the path you gave us. But I'm willing to bet you're actually pulling the entire repo, not some random subdirectory underneath it, despite what you say in the question, because that repo does have .pyc files in it.

The problem is that any time you import a .py file, it can rewrite the .pyc file, causing you to get ahead of the master. Once you get ahead of the master in some way that isn't tracked, you will need to merge, rebase, or otherwise clean things up if you want to pull or push. A good git tutorial will explain this.

But the right way to solve this is to just not check in .pyc files. There is almost never a good reason to do so, and plenty of good reasons not to.

There's a great collection of .gitignore files at https://github.com/github/gitignore (and the appropriate one will even be applied automatically if you use the Github website or client to create a new project). You'll notice that the Python one starts with .py[cod]. You should do the same.

If you don't want to use a .gitignore, this just means you can't use the -a flag anywhere; you'll have to manually manage which files are and are not checked in, and don't manually add the .pyc files.

If you have a good reason to check in the .pyc files, you probably want to prevent Python from updating them except when you choose to do so explicitly. In other words, during normal development, always run with the -B flag or PYTHONDONTWRITEBYTECODE env variable; then, when you're ready to push, delete the .pyc files and make Python generate them manually.

If you actually want to manage your .pyc files the way you're doing, and it's not an accident, and you just want to know how to manually merge your way out of an unexpected conflict: you do it the same way as with any other conflicting files. For example, stash, pull, unstash will give you the chance to manually pick one .pyc version or the other without screwing up anything else. (You have to know which one you want… but if you don't know that, you don't have a good reason to be managing your .pyc files this way.)

abarnert
  • 354,177
  • 51
  • 601
  • 671
  • Is there a way just to pull the ecomstore folder alone? – user1050619 May 02 '13 at 01:27
  • @user1050619: If you're asking whether you can only clone ecomstore in the first place, rather than the whole repo: You probably shouldn't do that, but the consequences aren't horrible, and it isn't too hard. "sparse clone" functionality is built into `git` nowadays. (If you have an older version and can't upgrade, you can find various scripts people have come up with if you google for "git sparse clone".) But first, consider whether you really want this. Why not just make ecomstore its own repo? (If you also want it to appear in the larger repo, that's what submodules are for.) – abarnert May 02 '13 at 19:53
  • @user1050619: If, on the other hand, you're asking whether you can pull just ecomstore into a clone of the entire repo… that's a much, much worse idea. The problem is that your repo tracks the upstream repo atomically—there's a revision that your entire repo is synced to, not a revision that each file is synced to. There are tricks that can make this work, but… really, why not just sparse-clone a separate repo (or convert your existing one)? – abarnert May 02 '13 at 19:58
  • @user1050619: If you decide you want to do a sparse clone, see [this blog post](http://jasonkarns.com/blog/subdirectory-checkouts-with-git-sparse-checkout/), which explains it all much more simply than the official docs. – abarnert May 02 '13 at 20:03
  • @abarnert..I will have a separate repository for each project..Just want to check on the folders and how it works....THanks once agains – user1050619 May 02 '13 at 20:27