1

i'm using github to host a git repository and i need to clone that repository in some machines (those machines are not for making changes into the code) they are only used to save a copy of the code of a software.

I use the following command line to clone the remote repository into local machines:

git clone -b master git://github.com/jquery/jquery.git jquerylocal

The problem comes when i need to synchronize (get the changes of files and new files added) the local folder named jquerylocal with the latest version, because my machine add files named .DS_Store and gives me the following error:

error: Your local changes to the following files would be overwritten by merge:
    .DS_Store

I would like to say git to ignore all files that i created in my local directorey and replace with the new ones and make new changes in existing files.

I'd also like to know how to say git to ignore some folders and files to be syncronized.

Thanks a lot.

eykanal
  • 26,437
  • 19
  • 82
  • 113
gustavomanolo
  • 787
  • 1
  • 9
  • 18
  • 2
    You should really consider a better title for your posts. "Git and github doubts" makes it sound like this would be doubting some functionality of git, or questioning how it would actually work in a certain situation. Possibly something like "How do pull all remote changes and overwrite any local changes with git?" – CodingWithSpike Apr 10 '12 at 20:09
  • 3
    Why are folks flagging this as "too localized"? This is a very common problem. If anything, this is an [exact duplicate of about two hundred posts](http://stackoverflow.com/search?q=git+DS_store), but it's definitely on-topic. – eykanal Apr 10 '12 at 20:32
  • possible duplicate of [Force git to overwrite local files on pull](http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull) – Andrew T Finnell Apr 10 '12 at 20:52

3 Answers3

5

You want to create a .gitignore file, which will instruct Git to do exactly as you ask; ignore files with certain filename patterns. In your case, you'll want to make a .Gitignore file with a single line:

.DS_Store 

This should be in the root of your Git repository.

If you've already checked in a few .DS_Store files, you'll want to have Git stop tracking them. You can use git rm .DS_Store for that purpose.

eykanal
  • 26,437
  • 19
  • 82
  • 113
  • And how do i sync new changes to old files and add new ones every time there are new changes in the github remote repository? – gustavomanolo Apr 10 '12 at 20:34
  • @gustavomanolo - You want `git push` and `git pull`, but that's a very basic question; I suggest you read up on [Getting Started with Git](http://progit.org/book/ch1-0.html). – eykanal Apr 10 '12 at 20:36
  • And how do i sync new changes to old files and add new ones every time there are new changes in the github remote repository? Wich command do i need to use without making changes in the remote repository? I just want to get the new files in to my machines overwriting the old ones no matter if i loose my local folder synched folder, i just want to not affect the remote repository files. – gustavomanolo Apr 10 '12 at 20:48
1

Create a file called .gitignore in the root of your project.

Edit the file and add .DS_Store to that file. git add .gitignore and git commit that file.

Then git rm all those .DS files. Push your changes.

Git Synchronization:

Pull changes

git pull

Push Changes

git push

All you need to do is git pull on the remote machine. If there are any conflicts those seem like files you shouldn't be committing as they appear to be automatically generated by your build system. Once you remove any committed .DS_Store files and added it to the .gitignore you no longer have to worry about synchronizing that file as it will be ignore by git.

Andrew T Finnell
  • 13,417
  • 3
  • 33
  • 49
  • And wich instruction do i give to git to syncronize the old files and add the new ones? – gustavomanolo Apr 10 '12 at 20:25
  • And how do i sync new changes to old files and add new ones every time there are new changes in the github remote repository? – gustavomanolo Apr 10 '12 at 20:35
  • And how do i sync new changes to old files and add new ones every time there are new changes in the github remote repository? Wich command do i need to use without making changes in the remote repository? I just want to get the new files in to my machines overwriting the old ones no matter if i loose my local folder synched folder, i just want to not affect the remote repository files. – gustavomanolo Apr 10 '12 at 20:48
0

If it is OK to delete the locally added .DS_Store files (and any other local changes) then you could do a git clean before you pull the new changes.

This question might also answer what you need: How do I force "git pull" to overwrite local files?

Community
  • 1
  • 1
CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138