Git: Apply Changes from Branch as Unstaged Changes

Sometimes I want to quickly save some code changes that I am not ready to commit into a real branch. For example, I might be in the middle of a long refactoring and there is a complete mess that I do not want to show up in version control history:

Git has the “stash” command which removes all uncommitted changes and saves them to a local data structure where they can be retrieve later. However, this comes at the disadvantage that stashed changes only live in your local environment – they cannot be synced to tools like GitHub or GitLab.

This is fine for small changes, but when you really need to make sure to keep your changes, there is a more permanent solution that also does not pollute your version control history.

Save Changes

You save your changes by committing them to a “dirty”, temporary branch (let’s call it temp_refactor:

  • git checkout -b temp_refactor
  • git add .
  • git commit -m "some trash commit"
  • git push

Your changes are now reflected in the temp_refactor branch and can be pushed to a remote repository.

Load Changes

When you are ready to continue, change to the branch you actually want your changes to end up at and do the following:

  • git checkout feature/my_normal_feature_branch
  • git checkout temp_refactor -- .

All your changes are now back as unstaged changes and you can continue your work.

Use Ansible to Deploy Software from git

Imagine you work on an application on a development server for several months until it is time to deploy it to a production system for the first time. Chances are, there are several necessary configuration tasks just waiting to be forgotten: firewall permissions, specific software libraries, file permissions and so on.

Ansible offers a reproducible and automatable way to take care of these configurational changes for you – and the beauty is: it does not depend on a specific Linux flavour and it works both for single-machine deployments and distributed systems.

If you were never wondering why your application exits with an HTTP error until you have noticed that the cache folder did not have the correct permissions, stop reading; if you have never forgotten which libraries you had to apt-get install before the Makefile finally completed without errors, this is not the guide for you. Otherwise, see how a simple 50 line yml file can take care of your deployment challenges.

Continue reading