I have a git repository where I store template files that I often use, I did a checkout of the latest version a couple of days ago and made local changes to these template files.
I just made change to the template files master repository and now I want to checkout the most recent version of my master branch but I don’t want to have my local changes deleted.
How can I merge the changes from the master branch into my working copy?
To take full advantage of the merge (or rebase) tactics of git, you could commit the changes to your local repository and then pull. Pull results in a merge between the remote and local repositories, which may be a fast-forward or a recursive merge depending on the upstream changes. You may even want to create a new branch for this (which you can then push to the origin if you want without affecting the master branch).
The stash could help you here, but you run the risk of the stash not being able to apply after the pull.
Simple example:
New branch example:
The latter merges the remote changes in
masterinto your localnewbranch, but bear in mind that in this situation your local copy ofmasterwould still be behind (i.e. if you then did agit checkout masteryou’d still need agit pullto get the changes).