Background:
- For all of the demonstrations in this series, consider you have two developers and one remote repo hosted in github
Scenarios for Merge-Conflict
-
Developer A is Creating the basic structure of project. This project uses python django and angularjs. so the basic folder will be the first commit Refer Here
-
Devloper B gets the latest version
-
Both Developer A and Developer B are working on Same files and they decide to update the remote repository
-
Developer B pushes the code to Remote Repository
-
Devloper A push will fail, he needs to get the latest version and when he tries to pull he gets merge conflict
-
Fix the code to be right
-
Add the changes and execute git commit now developer A can push changes
Scenario: Mutliple Branches
- QT decided to work on two version parallelly along with main development branch master
- release-a (apollo hospitals)
- release-b (continental hospitals)
- To do this we use branches in git
- Our branches will be as shown below
- To create a branch
git branch <branch-name>
- To Create the branch and move the head to new branch
git checkout -b branch
- To view all the branches
git branch
- To push the branches to the remote repository
git push <remote> <branch>
- Now if the developer B pulls the code he gets all the commits and also branches
Git – Merge
-
Normal Merge
-
Fast-Forward Merge:
- Now you want to merge the changes from release-C to master and master has not changed at all, creating a new commit will not be required and git just moves the master branches pointer to the latest commit ID on release -C
- note: If you dont want fastforward do merge with
git merge --no-ff <branch>
- Now you want to merge the changes from release-C to master and master has not changed at all, creating a new commit will not be required and git just moves the master branches pointer to the latest commit ID on release -C
Git – Rebase
-
Images
-
Commands
-
Interactive Rebase is also used to change the history of local commits
Git-Cherry Pick
Git Topics To be Covered Post Jenkins
- Git Protocols
- Git Hooks
- Branching Strategies
- Forking in Git Repositories
- Git Bare repositories
- making changes in history using interactive rebase
- Git Stash