tags:

views:

136

answers:

4

I use git for my source management, I have a local repository on my mac and a remote repository at github. They are BOTH suppose to be the same exact thing. I work by myself and I am the only programmer working on my web applications.. I can't get git to act right - with svn I could simply commit the code to the repository and BAM! The remote repository magically had the exact same files in it... Not in git, no, it just can't be that simple. I MUST read an entire damn book just to use the stupid thing.

So the question is, what is your development cycle like? I just want to have the exact same code at github as I have in my local git repository. Here's how I code:

I write code...add, edit, delete, modify files.... So I do this at the command line:

git add .  # this is *suppose* to add all files that are not part of the repository

git commit -m 'I commited this because...'

git push # send it to github

Now, after several weeks and hundreds of commits, github as slightly different code that I have in my local repository.

Please help me get this fixed before I trade git & open source for windows & svn or jump out of a window.

I'm sorry about the tone here, I'm just really upset that I keep finding inconsistencies in my source repositories. It's not a good feeling. I envision the one day where I lose my laptop and then github has old code in it. This just seems stupid.

Oh, one more thing... I don't want to have to always do git rm /some/long/path/to/file.txt when I remove a file. Is there an easier way? This is absolutely stupid and too time consuming.

Thank you for your help.

Br

+1  A: 

Github has a nice page here detailing on how to create, commit and push : http://help.github.com/creating-a-repo/ .

and particularly this:

git

You probably want git push origin master (you need to define origin before of course, read the information above) instead of just git push.

Another important thing to know is the git commit -a command, which simply commits all changed files etc., no need to git add them separately.

You might also want to check the output of git status to see if there are any suspicious things there which could be the cause of github not being an exact copy.

And FYI, svn is open source as well :)

houbysoft
well, what does "git push origin master" do? That's the same set of directions I used to setup my repository...
I just did "git push origin master" and it replied with "Everything up-to-date" - that's garbage, nothing is up to date. Github and my local repository have inconsistencies.
Same as `git push`, but it seems somewhat more correct to me. Anyway, another thing is to try to run `git status`, it will show you some information, and look there to see if anything looks inconsistent/causing the differenes in the two repositories (such as untracked files, etc.)
houbysoft
@2nd comment : then you didn't add all the files properly, or didn't commit everything. Again, try to check `git status`.
houbysoft
"git status" gives me a big list of files that I have deleted on my local repository, but still exist on the remote repository. This is my whole point. I want the two repositories to be exactly identical. How can I make this happen???????????????????????????????????
houbysoft
+1  A: 

"git status" gives me a big list of files that I have deleted on my local repository, but still exist on the remote repository. This is my whole point. I want the two repositories to be exactly identical. How can I make this happen???????????????????????????????????

If git status shows those files, you haven't added them to a commit and pushed it to the master repository yet. This is not Git's fault, it's yours. A version control system that automatically deleted stuff from the main repository because you deleted it on a local working copy would be a very dangerous version control system.

Do git commit -a (per http://www.kernel.org/pub/software/scm/git/docs/git-rm.html) and it'll add all those removals to a commit. Commit and push and you should be up to date.

ceejayoz
Ah, good answer: use of git commit's -a flag should remove the user's need for the "git add .", which should make it work much more like svn.
mattdekrey
I did "git status" and got a list of files, then did "git commit -a" followed by "git push" - now everything seems up to date. Is "git status" the way we tell if the local and remote repositories have any differences?
Git status does what it's named to do: it shows you the status of the local repository in deference to the currently tracked branch, which is in most cases, `origin/master`.
Damien Wilson
"git status" is basically a "Check for modifications" with the local repository. You can only push contents to the remote server that have been committed.
mattdekrey
+2  A: 

git add . actually only adds files and changes to files already in the repo. Try using git add -all . to actually add removed files.

If you're looking to just remove files, and not do the other changes, you can use git add -u . - for more information, check out the git-add man page here: http://www.kernel.org/pub/software/scm/git/docs/git-add.html

I've started using git over svn just recently, and, I must admit, I had some hardships switching over at first, too. Good luck!

mattdekrey
+1  A: 

It would help if you could specify exactly how the remote repository differs from what you expect (e.g. what is in your working tree). The only issue you have indirectly identified is that the remote repository still contains files that you have deleted from your local working tree.

If “deleted files still exist in the remote repository” is your only problem, then you should switch from using git add . to git add -A. The former will only add new files and stage changes made in tracked files. The later will add new files, stage changes made in tracked files, and remove files that are no longer in the working tree. You can use --all instead of -A if you prefer the more mnemonic option name. Using -A/--all will obviate the need for git rm each/deleted/file.

Chris Johnsen