How to git commit and push?

798 Views Asked by At

I must be missing something, almost always when I'm about to push my commit I'll get blocked because somebody else pushed a commit just before me and my changes (my commit) is not based on the tip of the remote any more.

At this situation I'll clone the repo again (in another folder) and manually change every file again, commit and hope nobody pushed just before me again. Sometimes it happens though and so I'll clone the repo in another folder a second time and same history repeats.

While observing commit history, with my approach I see a clean line, which I like.

I noticed other developers in the project are making a merge commit frequently after their own commits. I guess that's because they are facing the same situation as me (somebody else pushed before and changes are not based on tip anymore) but they are handling the situation in a different way (using a merge commit).

The problem is that these merge commits (at least the way they are being done) do not introduce anything, they just repeat the changes from previous commit because it seems developer did not issued a pull before push. In other words I'll say, commit history line is dirty.

I guess the merge commit approach is faster to handle than clone repo again and modify every single file again. But commit history line is dirty.

Project use just one branch, the master. And is hosted in a shared folder in local network.

I use to do git from command line but these days I'm using https://www.sublimemerge.com almost all the time.

How can I improve my commit/push workflow? Should I use other tools?

2

There are 2 best solutions below

4
Jacobm001 On

For start, it would be better if you did your development on a different branch. Even if your other developers insist on doing it this way, it doesn't prevent you from branching.

  1. Create a new branch.
  2. Do your work, committing to this branch as necessary.
  3. Switch to master
  4. Pull down new changes.
  5. Merge your branch into master
  6. Push the changes.

Alternatively, if you really insist on not using branches and you don't like these merge commits, you could do a rebase.

6
V Maharajh On

At this situation I'll clone the repo again (in another folder) and manually change everyfile again,

This is quite tedious.

Instead, do this:

git fetch
git rebase -i origin/master 

This will automatically merge all of the changes that other folks make. In cases where the changes conflict with yours, it'll let you resolve those conflicts.

Then finally

git push