. Advertisement .
. Advertisement .
Different branches are usually created for different features when you develop software with the Git tool. Yet, changes to master are not always automatically added to branches.
The following tutorial will introduce you to how to pull changes into another branch.
How To Pull Changes Into Another Branch
There are three ways to pull changes into another branch:
Method 1: Use The git merge
To use this method, you need to switch to your working branch. The checkout command will update the files according to the specified working branch.
Here is the command to execute the dev branch:
git checkout dev
Then use the following command to update the branch:
git fetch origin
This command is used to download refs and objects from other repositories. It will help you pull changes from another branch into repositories. Here is how the command updates your main branch.
git merge origin/main
This command transmits the named commits’ changes to the current working branch.
You should also adjust git merge origin/master when being on your aq branch:
git checkout aq git merge origin/master
~/ test (main) >>> git checkout dev Switched to branch ‘dev’ ~/ test (main) >>> git fetch origin ~/ test (main) >>> git merge origin/main Updating 92655fa..545e144 Fast-forward file2.txt | 0 1 file changed, 0 insertions (+), 0 deletions(-) create mode 100644 file2.txt
Method 2: Use The git rebase
Use the git checkout dev command to switch to the dev branch. Now it is time to use the git fetch origin command to update any change to this branch.
The git rebase with the git rebase origin/main command reapplies commits on another branch’s top.
~/ test (main) >>> git checkout dev Switched to branch ‘dev’ ~/ test (main) >>> git fetch origin ~/ test (main) >>> git merge origin/main
Successfully rebased and updated refs/heads/dev.
Method 3: Use The git pull
In this method, you will still use the git checkout dev command to switch to the dev branch.
The git pull command is used to integrate with other branches. Don’t worry if your history doesn’t share the same ancestor when merging projects. In this case, use the –allow-unrelated-histories parameter.
Type the command to get changes from the main branch:
git pull origin main --allow-unrelated-histories
~/ test (main) >>> git checkout dev Switched to branch ‘dev’ ~/ test(dev) >>> git pull origin main –allow-unrelated-histories From *branch main -> FETCH_HEAD Updating 0fdeec5..cd9c78a Fast-forward file3.txt | 0 1 file changed, 0 insertions (+), 0 deletions (-) create mode 100644 file3.txt
How to pull changes into another branch? There are three main methods to accomplish this. The git pull origin master merges the master branch’s contents with yours.
There will be some unexpected merge conflicts so don’t forget to resolve all commits before proceeding.
Leave a comment