We're currently having a revamp of our website, therefore we created a new branch revamp
from main
.
Everybody does their changes in the revamp
branch.
Now following scenario happened:
Monday: My coworker committed "commit A".
Tuesday: I committed "commit 1", "commit 2" and "commit 3".
Wednesday: My coworker wanted to commit "commit B". However, when trying to push his changes, GitHub Desktop notified him, that there were changes that he hadn't pulled yet (my commits 1, 2 and 3 from tuesday)
Naturally, he fetched my commits and then hit "push". GitHub Desktop created two commits:
Thursday: When pulling the new changes, my changes 1, 2 and 3 were gone from the codebase. They were still in the GitHub Desktop History. However when inspecting his commits in the History, "commit B" only showed some unrelated changes and "Merge branch 'revamp'..." shows No files in commit
. I could not see, where the code was removed.
It took me a while to figure out, that I can only see the deletion when hitting the button "Compare changes" on https://github.com on the "Merge branch 'revamp' into revamp" commit. (The URL looks somewhat like https://github.com/company-name/project-name/compare/18511cb70baa1b55de4b9b84366a82e8d26eb9a2...9a619b35d10a62d73b2cbf4e0ae9f71e87008822, I think it's git diff, but not too sure.)
I tried:
There are no changes to commit
(remember, it says No files in commit
).Is this related to GitHub Desktop? I'm not too familiar with the git commands, so maybe GitHub Desktop used the wrong approach of merging, or simply scrambled up stuff(?)
Any help would be highly appreciated! Cheers, Boris
Edit: Here's how it looks on https://github.com when using the "Compare changes":
Everybody does their changes in the revamp branch
Well, that's the problem. You have multiple people making their own commits on, and pushing, one and the same branch. That is a recipe for trouble, and trouble is exactly what you're getting.
Instead, everybody should do their "changes" (i.e. make commits) only an their own individually created local branch, and should push that branch to GitHub where the branch can be merged using a pull request. That way:
(1) The issue "when trying to push his changes, GitHub Desktop notified him, that there were changes that he hadn't pulled yet" will never happen (unless someone rewrites history within their own branch, and in that case pushing with force is fine).
(2) No one's commits will stomp on anyone else's commits; all the commits will be merged to, and thus interleaved on, the ultimate target branch revamp
.