So the background is I have a repo which is a production repo and I have a test repo which is a clone of that production one. I have made some changes to that cloned one.
Now it's been a while and the production one has had many updates and commits since.
I want to update my cloned repo with the all the changes of the production one to the latest commit on my cloned repo but also keep some of the changes I've made on my cloned one.
How can I go about doing so?
CodePudding user response:
on your local machine, setup remotes to both repositories
git remote add prod <produrl>
git remote add clone <cloneurl>
do a git fetch
to pull down all of the different branches
checkout out the cloned branch you want git checkout -b localbranch clone/<branch>
merge in the changes from production git merge prod/<branch name>
CodePudding user response:
As a relative newcomer to Git, I can sympathize - it can be a daunting learning curve!
One of the things to grasp about Git is that it is generally undestructive and will not readily wipe out any changes on your local version. It just looks at the changes that have been made to the upstream version since the last time that you cloned or pulled from that upstream version, and tries to apply those changes to your local version. So if the upstream version of file "x" has an added chunk of code, it will add the same chunk of code to the local version of file "x". But if you have added or changed a file "y" on your local version, then as long as the upstream version of "y" was not changed since the last "pull", then Git will not be interested in doing anything about that file, and will let your local updates stand.
Separate fetching and merging will not be necessary in most situations - you just need to make sure that your local version has no uncommitted changes ("git status" should not show any files), and then run "git pull". Your cloned version will probably be already implicitly linked to the upstream version - you can run "git remote -v" to check this - so you do not need to muck about with "git remote add" etc.
The only complication comes when you have made local changes at the same time as the same files on the remote version have undergone different changes. In that case running a "git pull" will evoke a response from Git telling you what you need to do. Don't panic; just read the instructions carefully and it will be simpler than you think.
This is all a great simplification of the procedure, and I am not an expert, so take what I say with a pinch of salt, but you just have to dive in and see what happens. You can almost always undo an update if it goes wrong, and as an additional reassurance, the earlier suggestion about creating a new branch to "save" your work is good.