Home > Blockchain >  How to merge in git changes in the script that were uploaded but not pulled in my version?
How to merge in git changes in the script that were uploaded but not pulled in my version?

Time:10-31

So, I have a project where me and a colleague work both in the same script. She already made some changes and uploaded to git. I have also done other things in the script and I now I would like to push also to the repository.

However, I am afraid the one of 2 things happen:

1- I pull her changes and I loose all my updates in the script.

2- I push my changes and I could get an error because the version is not the most recent one / or her changes are discarded.

What is the best way to deal with this type of co-working?

CodePudding user response:

I pull her changes and I loose all my updates in the script.

Why would that happen? A pull is a merge, not an override. Its primary directive is to combine the changes from both sides of the merge. If it can't do that automatically it will pause to let you straighten things out manually.

So add and commit your current working tree and then just do the pull. If it doesn't work out as hoped, you can undo the merge with a hard reset and you'll be back where you were before. But don't worry, things will be fine.

You might still have to straighten things out a bit after the merge. But that's fine too.

In short, having two people work on the same file simultaneously was perhaps silly and to be avoided if possible, but it's hardly a disaster.

CodePudding user response:

That scenario is why we have git.

  1. Pull changes from repository

  2. git will recognize that you're merging changes and will show you which parts of code were changed

  3. git will offer you options to accept incoming changes, keep your version of the code or decline incoming changes. it is up to you what you'll do with every part.

  4. you can continue working on script

  5. commit it and push to repo for others to see your changes

they will go back to step 1 and repeat the process.

If you're afraid your changes will disappear you can stash your changes or just copy your script to another folder until you'll gain confidence in working with git.

  • Related