Monday 21 November 2016

Git : Best practices based on previous version control variants

In trying to get my head around the very different basis on which Git is built, I've identified the following sequence of steps in order to ensure logical interaction with Git (local and remote repository)

  1. git add : Add or remove your changes to the current local index (local repository)
  2. git stash : Move your local changes as committed to the local index to a local branch index and remove it from the current local index (This is necessary in order to pull the latest code changes from your Git remote repository...without maybe causing a merge push request)
  3. git pull : Synchronise your local repository with the remote repository by pulling in the remote changes into your local index.
  4. git stash pop : Restore your changes which have already been added to your local index. If you remember, you will know these changes have been moved from the local index to a local branch index. By executing "stash pop" your existing changes are moved back to the local main index. This might also cause you to have to merge your changes...depending on the state at which the remote repository was synched.
  5. git commit -m "<commit message>" : Commit the changes you have made to your local Git repository with the given commit message.
  6. git push : Commit the changes you've commit to your local repository, also now to your remote repository.
I hope you find it as helpful as I did.