I am working on project which I have cloned from main repository branch . Now I want to push changes to a new branch( i will create new branch for me only) and then raise merge request to main branch. The problem i am facing is that project main branch is being updated continuously so for that I have used git pull command but that does not shows any changes which are on remote when I open that on vs code i am getting the same code which was available when I first cloned the repository.
Now there are chances that I will change some code in same file which was updated in main branch and i may know about the changes then what will be the best way for me to push and check changes
I used git pull command and i thought I will get new code when open that in vs code but that was old code
CodePudding user response:
I used git pull command and i thought I will get new code when open that in vs code but that was old code
As you said in your question for main
to have the changes in your feature_branch
you need to raise a merge request (aka pull request). When trying to keep your branch up to date with changes in main
you also need to merge.
There are two ways to achieve it:
- via
pull
&merge
:- checkout main,
- pull
- checkout feature_branch
- merge main (which now has the changes made by others)
- via
fetch
&merge
fetch origin main
-> this downloads changes made by others to a local branchorigin/main
(butmain
[noorigin/
] doesn't get the changes)merge origin/main
(notmerge main
)
You can find the steps in How to take latest changes from dev branch to my current branch.
You could pull the remote main
into feature
not via main
/origin/main
but that would sooner or later end up in a mess - this way is only for advanced use cases and users.
CodePudding user response:
first we use ---> git checkout {your branch name} for go to your branch after that you will do any changes Here and then git push origin {your branch name} which is used to push the changes on this branch not reflect your main branch. you have not used to git pull simply use git checkout {your branch name} to see changes on main branch or your branch.