Git Branching
- Create a new folder and make it a repository
- add one commit and rename the default branch to main
- create one more commit on main
- Lets create a branch called as sprint0
- lets make one change in sprint0 in src/main.py
Fast Forward Merge
- We want changes done in sprint0 to be merged to main
- The merge command is
git merge <source-branch>
i.e. you should be in target branch
- Fast forward merge happened which moves the main to the latest commit of sprint 0 branch.
- Before Merge
- After Merge
Three Way Merge
- Lets create a commit on main branch and git graph should be as shown below
- Current view
- Lets merge the changes into main
- We get merge conflict as line 1 of src/main.py is conflicting
- now make the changes and add them to staging area and commit to create a merge commit
- Merge commit is a special commit, which has two parents
- note: IF you are new to vi editor Refer Here
Exercise
- Create a git repository
- create three files called as README.md in
- src
- test
- build
- create a commit
- create one more commit by editing README.md in src
- main will have two commits
- represent this in graph with HEAD and master in the graph
- Now create a branch sprint0 from master
- From sprint0 create two branches
- sprint0_poc
- sprint0_dev
- Update the same in graph
- Now checkout to sprint0_poc and create a folder called as poc with Readme.me, update the graph
- Now checkout to sprint0_dev and create a file src/main.py
- merge changes from sprint0_poc tp sprint0_dev
- Delete the sprint0_dev