Wednesday, May 19, 2021

Git Basics - rebase

 Rebase conflict

git status -> clean master

mate simple.html --> add some content and save

git commit -am "before rebase conflicts"


git checkout -b conflict-branch

mate simple.html -> add some to conflict

git commit -am "adding to content"


switch back to mater

git checkout master


mate simple.html ---> changes to conflict

git commit -am "add contect 3"

git status -> clean

git log ---oneline --graph --decorate --all


you can see commits in two branches


Abort rebase

git checkout conflict-branch

git difftool master conflict-branch


let's rebase

git rebase master

--> Conflict


So for now we do not want to proceed with this and need to revert or abort our rebase


git rebase --abort

git status --> verify, clean and still on "conflict-branch" branch

git log ---oneline --graph --decorate --all

you can see nothing has changed


Rebase and conflict Resolution

let's go to rebase again


git rebase master

--> conflict


git mergetool -> resolve conflict

git status -> modified: simple.html

git add simple.html 

git status Now we have resolve all the issues with commit.  Let's continue


git rebase --continue

git log --oneline --graph --decorate --all


Pull with rebase

git status -> clean , we are 'master'


synchronize with Github

git pull origin master

git push origin master


git status -> upto date with'origin/master' , clean


mate simple.html -> add some changes

git commit -am "local: updating simple.html"

git status -> clean, 1 commit ahead of 'origin/master'


2. Log with browser and change 'index.html' --> remote change

git status -> clean, 1 commit ahead of 'origin/master'

Note: no change in the message


As our local is 1 commit ahead of 'origin/master' let's pull and synchronize

we use 'fetch'  here

fetch - non dstructive command - simply updates the references

1. git fectch origin master

git status -> origin/master and local master diverged. have 1 and 1  different commit each.

2. Now we really want to work, 

but 'not ready to merge' my commits

Keep my commits ahead of Github - remote repo ( getting benift of changes done in Github)

you can do with 'git pull' 


git pull --rebase origin master --> rebase, not a normal merge

We have rebased our changes from 'Github' on top of our 'master' branch

git status ->clean, your branch is ahead of 'origin/master' by 1 commit.


git log --oneline --graph --decorate --all

in log , we can 'origin/master' and 'master' branch


Clean up push to Github

git status

clean

your branch is ahead of 'origin/master' by 1 commit.


git branch

* master

conflict-branch


we don't need that created branch, so let's delete

git branch -d conflict-branch

git branch

* master


Next, synchronize with Github

git pull origin master

*branch master ->FETCH_HEAD 

Already up to date


Note: Although we have different commits on Github than in locally , we have incoperted those changes using 'rebase' earlier.


git push origin master 

you can verify from browser login to remote Github

No comments:

Post a Comment