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:
git add .
git commit -m 'My local template changes'
git pull origin master # fix any conflicts
New branch example:
git checkout -b newbranch
git add .
git commit -m 'My local template changes'
git pull origin master # fix any conflicts
The latter merges the remote changes in master
into your local newbranch
, but bear in mind that in this situation your local copy of master
would still be behind (i.e. if you then did a git checkout master
you'd still need a git pull
to get the changes).
you can always save you local changes in the stash, pull the latest changes and then apply your saved changes again.
git stash -- save your local changes
git pull -- get latest changes from remote
git stash pop -- apply your saved changes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With