DevOps session 13: Automate git SETUP using bash scripting.

Before starting with GIT merging session, completed previous session on Git branching .
Let us consider same example from previous session, Developer 1 working on dev-login branch and Developer 2 working on dev-signup branch.
In dev-login branch -login.txt file is created and pushed to GitHub
In dev-sign branch - signup.txt file is created and pushed to GitHub.
In main branch - no files are created
Now we want to combine two features login and signup to main branch. To do that GIT providing us merging concept.
Follow the below steps to merge the branches:
1. First I want to merge the dev-login branch with main branch. Switch to branch where you want to merge the code from other branch(eg: main in my case). use the below command to merge the code from dev-login branch to main branch.
You should be on main branch before using below command.
CMD: git merge dev-login
2. Follow the same steps and merge code from dev-signup to main branch.
You should be on main branch to use below command.
CMD: git merge dev-login
Once merge is successful. You can check if signup.txt is created in main branch.
3. All the changes you are made saved on local repo. If you want to make same changes to your GitHub repo. You need to push the code.You should be on main branch to use below command.
Follow below steps:
Verify from your GitHub repo:
Before merge and pushing the code:
Merge conflicts means you are facing some issue while merge the code to main or other branches.
Reason:
1.Multiple people using same file created and making the changes locally.
2.When a file is deleted by another team member.
3.When you created a file, which is already present in another branch and try to push to main branch.
Let us consider an example.
Developer 1 working on dev-login branch
Developer 2 working on dev-signup branch
Developer 2 created a signup.txt file in dev-signup branch
Develop2 1 also created signup.txt file in dev-login branch
Now Developer 1 and Developer 2 want to merge the code from dev-login and dev-signup branches.
Here we will get the conflicts because in same branch no two files will be with same name.
Solution :
You can use git merge tool command to get some hints to resolve the conflicts
Now to resolve the issue, we can switch to dev-login branch and rename the signup.txt file to signup2.txt.
Then commit the code and push to dev-login branch.
As a next step ,switch to main branch and check the signup.txt file if any extra content is added to file. In that case ,we need to edit and remove the extra lines added in the file and save it.
I have use vi editor to to edit the file. follow below steps
cmd: Vi filename: file will open in editor
A console will open, to start insert mode press "i" from keyboard.
Remove extra lines and to exit insert mode ,press "ESC" from keyboard.
Then ,to save and quit the file, we can type " :wq " at the bottom of file.
Use the command git merge dev-login shown above to merge the code to main. There will be no issue and code is merged from dev-login to main with out any issues.
Signup2.txt is copied to main successfully and shown below.
Comments
Post a Comment