I'm new to git and I'm not sure how it works.
If I I'm working on my branch and someone push changes to the main branch, if pull from main will my work on my branch get overwritten? Even if the new changes are not on the files I'm working on? Or it will just update the files without changing my work?
Thank you.
CodePudding user response:
No, the changes are on different branches, and they won't affect each other. Git will just move the history forward on the main branch with no effect whatsoever on your current branch. If you want the changes on the main branch applied to your branch or vice versa, you would have to merge.
If you are also on main and the changes are on different files or different area of the files. Git will try to do automatic merge. If there are conflicts, i.e. the changes are in the same area of the file, git will ask you to manually resolve it.
CodePudding user response:
If I understood your question correctly, you want to know if you can pull code from main, and keep your code as it was before you pulled. You can, but ideally you should be up to date with main, so no conflicts emerge later on. OK, so what you would want to do, (assuming you want the code that's on main) is:
- change to, or create a new branch
- Pull the code from the main branch
- Make any changes you want.
After you are finished making changes, you can push to main.