Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Update an outdated branch doing a rebase

Basically, you have to checkout to the updated branch – for this case develop branch - , do a git fetch –
git pull, and after that checkout to the outdated branch and do a git rebase updated-branch name

In this example develop was previously worked and the changes went ahead of my 170002 branch so I
had to update my branch doing a rebase

root@CR-IT00107:~/repo-project# git branch


hotfix-a
* hotfix-b
main

root@CR-IT00107:~/repo-project# git checkout develop


Branch 'develop' set up to track remote branch 'develop' from 'origin'.
Switched to a new branch 'develop'

root@CR-IT00107:~/repo-project# git fetch


remote: Azure Repos
remote: Found 3 objects to send. (0 ms)
Unpacking objects: 100% (3/3), 417 bytes | 417.00 KiB/s, done.
From https://dev.azure.com/carloschacon-my-devops-org/repo-project/_git/
repo-project
8377dce..df16d7b develop -> origin/develop

root@CR-IT00107:~/repo-project# git pull


Updating 8377dce..df16d7b
Fast-forward
FileA | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

root@CR-IT00107:~/repo-project# git rebase develop


Current branch develop is up to date.

root@CR-IT00107:~/repo-project# git branch


* develop
hotfix-a
hotfix-b
main

root@CR-IT00107:~/repo-project# git checkout hotfix-b


Switched to branch 'hotfix-b'
Your branch is up to date with 'origin/hotfix-b'.

root@CR-IT00107:~/repo-project# git rebase develop


Successfully rebased and updated refs/heads/hotfix-b.

Resolving Merge conflicts from Azure DevOps

Sometimes you have git fetch and git pull from the branch you are going to merge since the target merge
might be out of date too

Sometimes target branch is up to date, so a git fetch and pull is needed like below

# git merge main


Already up to date.

root@CR-IT00107:~/try-try-repo# git fetch


remote: Azure Repos
remote: Found 3 objects to send. (0 ms)
Unpacking objects: 100% (3/3), 357 bytes | 357.00 KiB/s, done.
From https://dev.azure.com/carloschacon-my-devops-org/repo-project/_git/try-try-repo
bd4fc53..dabebeb main -> origin/main

# git pull
Updating bd4fc53..dabebeb
Fast-forward
fileA | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
After target branch is up to date, merging conflict popup

So if you run this command in the source branch, a new screen will popup to fix in the Merge Editor

# git merge main


Auto-merging fileA
CONFLICT (content): Merge conflict in fileA
Automatic merge failed; fix conflicts and then commit the result.
root@CR-IT00107:~/try-try-repo# git status
On branch branch-B
Your branch is up to date with 'origin/branch-B'.

All conflicts fixed but you are still merging.


(use "git commit" to conclude merge)

Important in this example I used develop target branch but the command would be for this example git
merge main

Once changes to fix merge are done run a git commit as next command and Sync Changes in VS Code GUI

# git commit -m "fixing"

[branch-B 1392391] fixing

Best practice, always to do a pull before doing a push, valid before using fetch

You might also like