Git Rebase
Git rebase is a command that allows you to change the order or content of commits in a Git branch. It does this by applying the changes made in one branch onto another branch.
Scenario based example on how Git Rebase works:
Suppose you are a developer working on a project and you have two branches, feature A and feature B. You have been working on feature A and have made several commits to that branch. However, you now realize that some of those changes should have been made on feature B instead.
Here's how Git Rebase can help:
Identify the branch: Use the
git branch
command to identify the branch you want to apply changes to. In this case, it's feature B.Use Git rebase: Run the command
git rebase feature A
. This will apply the changes made in feature A onto feature B, so that any commits made in feature A will now be included in feature B.Resolve conflicts: If there are any conflicts between the two branches, you will need to resolve them before you can continue. Use the
git mergetool
command to resolve any conflicts.Commit changes: Once you have resolved any conflicts, commit the changes using the command
git commit -m 'merged feature A into feature B'
.Git Merge
Git merge is a command that allows you to combine changes from one branch into another branch. It creates a new commit that combines the changes from both branches.
Scenario based example on how Git Merge works:
Suppose you are a developer working on a project and you have two branches, feature A and feature B. You have completed work on both branches and want to combine the changes into a single branch.
Here's how Git Merge can help:
Identify the branch: Use the
git branch
command to identify the branch you want to merge into. In this case, it's feature B.Use Git merge: Run the command
git merge feature A
. This will combine the changes made in feature A into feature B, creating a new commit that includes the changes from both branches.Resolve conflicts: If there are any conflicts between the two branches, you will need to resolve them before you can continue. Use the
git mergetool
command to resolve any conflicts.Commit changes: Once you have resolved any conflicts, commit the changes using the command
git commit -m 'merged feature A into feature B'
.
GIT Fetch and Git PULL :
In git hub repo - having prod, stage, dev,qa, and in git local repo has only on-branch dev. Git pulls the origin dev (remote dev and local dev will be in sync). i.e it's a branch-to-branch merge. but in git fetch, all the branches will be merged to local. (dev branch)
git conflicts:
In git rebase commit will be linear fashion. The whole history will be preserved. Instead in merge new commit will be a recent commit.
A soft reset will be kept in its staging area for your decision where as in hard reset will be done forcefully even though conflict arises and will be wiped.
Create a git repo, give access and deploy the branch to Jenkins
Diff between fetch and clone? -Clone will master/main branch whereas in fetch all the branches will get it in locally.