How to Avoid Git Merge Conflicts and How I Almost Lost My Head

Several weeks ago, I had made some application changes to one of my customer's systems.

Unfortunately, these changes did not have the desired end result; and after a couple of days of performance analysis, I decided to rollback the changes. A very common practice no doubt. I simply checked out the hash of the last commit from before I pushed new work to the repository.

ubuntu@server:~/project $ git checkout <hash_id>  

I restarted the application with the repo rolled back to the commit I had chose. All systems comes to life and all was well once again.

The client's team and I documented the results from the code changes I had made, reviewed the performance metrics from the two days the code had been implemented, and created a game plan for how to make the data collection, data mining, metrics and counting more efficient.

The next day, back in my local environment, I make the necessary code and software changes and tested locally.

Finally, I committed my work to the repository. I test the new code for a full two days in the AWS-LS DEV and STAGE environments, which I call Production Zero.

Everything seems to be working nicely. After a quick call with the client's decision maker, we agree to roll out these changes again.

I log into the terminal on the application server; I am about to sync my repo and pull down my latest changes when I remember...

I have a detached HEAD.

Man, am I glad I remembered that before I started running Git commands in my console.

Catastrophe was avoided by simply checking out the master branch. The master branch has the HEAD pointed at the last commit I had made and synced with the repo when I made the changes the first time around.

In my console...

ubuntu@server:~/project $ git checkout master  
ubuntu@server:~/project $ git pull origin master  

Now all production systems are back up and running smoothly; collecting and counting data with a ~ 50% reduction in task run times on the application server and a huge improvement on the database server memory and CPU utilization...

Git Commit

This experience reminded me of a poem.

Git Frost Poetry

Avoid merge conflicts.

Always remember your HEAD!

Craig Derington

Espousing the virtues of Secular Humanism, Libertarianism, Free and Open Source Software, Linux, Ubuntu, CentOS, Terminal Multiplexing, Docker, Python, Flask, Django, MySQL, MongoDB and Git.

comments powered by Disqus