views:

43

answers:

1

I've got a big problem but I bet it's easy to solve. I'm developing a website together with a friend using GiT for versioning control. We've just modified different parts of the same CSS file and then commited, then he pushed his commit. We're both using master branches in local and remote repository for we don't know how to deal with it very well. He pushed his commit to the remote repository, I don't.

What happens is. In the remote repository we have a file with A, I have a file with B and I want it to have A and B together in the remote and our local repository

What should I do? I'm also accepting some suggestions about how we can keep on developing the website in a way we don't have too much problems to deal with it (maybe creating branches, some techniques or patterns we should follow, or anything else 'cause i'm new at versioning control)

+1  A: 

First, use git pull to download his changes into your local repository, then resolve any conflicts that git will inform you about.

when you're done with it, commit and push the changes.

Mewp
I'm gonna try it. **Edited**: I'm trying to fetch (is there difference between `fetch` and `pull`?) and I'm getting `! [rejected] master -> Codaset/master (non-fast-forward)`. What is it?
Rodrigo Alves
@Rodrigo Alves: From the git manual: "[`git pull`] runs `git fetch` with the given parameters, and calls `git merge` to merge the retrieved head(s) into the current branch."
Mewp
I'm getting `error: Untracked working tree file 'public/images/Thumbs.db' would be overwritten by merge. Aborting` even with pull :S
Rodrigo Alves
It happened because your friend has commited `Thumbs.db`, and your branch doesn't track it. The simplest solution would be to just remove Thumbs.db from the directory, and then pull. Also, you should remove it from further commits (using `git rm`), as it'll only cause problems for both of you.
Mewp
I can't find this file, neither I could use `git rm` (it says it failed). Is there any way to delete/revert (I don't know the correct name) the commit he did, then commit again without Thumbs.db?
Rodrigo Alves
The file is hidden, and `git rm` will work only when you have the file committed (your friend can do it). As for *amending* the commit, it's possible using `git amend`, but shouldn't be done after pushing. Although he could always push a new commit. By the way, you should read http://progit.org/ if you want to know more about git.
Mewp
I think it worked now. Thanks!
Rodrigo Alves
By the way, I noticed that `git pull` merged automatically, which worked perfectly for *A* and *B* were separated parts of the file. It made me wonder: what if *A* contained *B* or the opposite? How would `git merge` handle this?
Rodrigo Alves
Probably without conflict. As long as `git diff` shows no changed lines (i.e. only additions or deletions), there should be no conflict.
Mewp
I think you misunderstood. Example: **css.css in computer 1** `#container { background-color: white }`, **css.css in computer 2** `#container { background-color: black }` and **css.css in remote repository** `#container { background-color: yellow }`. There's no way **GiT** could auto-merge this. What would happen here?
Rodrigo Alves
One of the computers would have to pull from remote (since any non-fast-forward push is rejected). `git pull` would tell the developer about conflicts he needs to resolve, then he'd resolve them by editing the conflicting files (conflicting changes are annotated in the files themselves), and commit the changes he made, completing the merge. After that, he would push the commit. Then the other computer would repeat steps above, resolving any conflicts.
Mewp
Note that I'm assuming that the remote needs merge (i.e. another developer pushed a change that wasn't pulled on either of the computers) -- if it doesn't, the first push would be fast-forward and not cause conflicts, so only one of the computers would have to do the steps above.
Mewp