1

When using github, this is what I usually do:

  • git pull to make sure if everything is up-to-date
  • git add . to add all my changes
  • git commit -m "some message" to commit my changes
  • git push to push my changes

After every change on my local files, I do the same above operations and go check on the website. The changes are there and everyone can see them. They exist on both local and remote repos. But once in a while, all my commits disappear and they're somehow discarded. I noticed that this happen whenever a colleague working on the same repo makes a change.

If this helps:

  • git log shows that my commits are logged

  • git checkout master says that I am already on master.

  • My Github profile says that I committed X number of commits to the repository, but when I click on them, it says "commits not found".

When on the master branch, are git push and git push origin master different?

I would like to know If I am doing something wrong here, so I can avoid doing it in future commits.

Omar
  • 139
  • 1
  • 7
  • When you check with `git log`, do they appear? – Syden Jan 18 '17 at 15:28
  • @Syden yes they appear – Omar Jan 18 '17 at 15:29
  • You push to your own branch or to `master`? (or you haven't pushed yet) More info would help. – Syden Jan 18 '17 at 15:31
  • So the commits are indeed logged, what you don't see are the changes you've done in the remote repo files? – Syden Jan 18 '17 at 15:41
  • So after making a change to my files in the local repo, I use `git pull` to make sure everything is up-to-date, `git add .`, `git commit` and then `git push`. And when I check on Github (website), the changes are all there. But later on, after my colleague makes a change, they disappear, like they were discarded or something. If it helps, `git checkout master` says I am already on master. – Omar Jan 18 '17 at 15:53
  • Just to clarify, you make the `pull` after making changes in your local repo? Ideally you would `pull` before starting to work on changes, `pull` basically does a `fetch` & `merge`, so that is what could be overriding your changes. On a side note if that's not the case maybe your other contributor is not following the same procedure? – Syden Jan 18 '17 at 16:23
  • Basically, we are working on different files. And most of the times my files are new. So, I assume when I do a pull after making the changes. It does not affect much. And I can see the changes on the remote repository (website, master branch). The problem is when he makes a commit, all my changes are gone. They're not even in the history. It's like he is creating a whole new repository every time he makes a change. – Omar Jan 18 '17 at 16:30
  • Maybe he's not pulling to update therefore just pushing his changes? – Syden Jan 18 '17 at 16:34
  • @Syden Thank you so much for your time. So, I understand that, aside from pulling after the changes, my procedure is correct. I will check with my colleague. – Omar Jan 18 '17 at 16:37
  • You are welcome, so far with it seems correct on your end, but if you gather new data feel free to share it and maybe we can isolate what's wrong ;) – Syden Jan 18 '17 at 16:39
  • Yes sure. I will keep this thread updated. – Omar Jan 18 '17 at 16:56
  • sure that git reports no error during operations ? – jo_ Jan 18 '17 at 17:05
  • Sounds like your colleague is occasionally accidently force pushing (or resetting) the work you pushed to that branch. Shared write permissions does give opportunities for such misunderstandings. – Philip Oakley Jan 18 '17 at 17:47
  • I wonder if your colleague is doing a `rebase` of some of the public commits? – PatrickSteele Jan 18 '17 at 18:34
  • 1
    @Syden mystery solved: my colleague was using `git push --force` as @VonC suspected. – Omar Jan 18 '17 at 21:15

1 Answers1

2

The problem is when he makes a commit, all my changes are gone. They're not even in the history. It's like he is creating a whole new repository every time he makes a change.

That would only happen if he forced a push

git push --force

On GitHub, you could at least protect your master branch.

When on the master branch, are git push and git push origin master different?

You can check the output of git branch -avv: it should show that master has an upstream (remote tracking) branch origin/master. In that case, git push is enough.
See "Why do I need to explicitly push a new branch?"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    thank you, and thank you all for your input. This thread was really helpful and full of information. Indeed, I just asked my colleague and he admitted using `git push --force`. Apparently he had some issues himself and he used `git push --force` without thinking about the consequences :( So, at the end what I was doing was correct, since I was using `git pull` and `git push` on my local HEAD branch which is tracking `origin/master`. Thanks! – Omar Jan 18 '17 at 21:13
  • great catch VonC! – Syden Jan 18 '17 at 22:01