DevOps session 13: Automate git SETUP using bash scripting.

Image
  Bash scripting: A Bash Shell Script is a plain text file containing a set of various commands that we usually type in the command line. It is used to automate repetitive tasks on Linux filesystem. It might include a set of commands, or a single command. For example ,to install GIT we need to update the packages, then install git and check if installation is done using Linux commands. We can write all the command in a .sh file and we can execute the file to do all the steps mentioned above. Lets start with example from hello-world. 1.Open terminal and check the root of the bash using below command. CMD: which bash you can see path like  /usr/bin/bash or /bin/bash . 2.Create a hello-world.sh file and paste the below lines. CMD: nano hello-world.sh You can see editor ,add below lines #!/bin/bash # declare MSG variable MSG="Hello World" # print variable on a screen echo $MSG To save the file use CTRL+X, then CTRL+Y and press ENTER 3. To execute the file we need to ad...

DevOps session 11: Git branching & best practices

 


Let us consider an example your in team where developer 1 working on feature1,developer2 working on feature 2 etc.

With out branching if the developers push and pull the code daily, which will leads to a confusion and code duplication or removal of code which might impact other features.

So git provides an option to create multiple branches, So that each developer can create there own branch and then update the code, push code to their own branch ,finally merge with main branch.

Eg: Developer 1 creates a new branch name: dev-login

      Developer 2 creates another branch  name: dev-signup.

So, Developer 1 and Developer 2 can work on their branch and once every thing is done. They will come together to merge the Login and signup branches to main.


Git branching commands:

1. git branch: Use to display all the branches on currently working repo(in our example devopsDemo)


2. git branch --show-current: Display the name of current working branch.

 


3. git branch branch-name: We can create nee branch using this command.

    eg : git branch dev-login ,new branch with dev-login name is created.



4.  git switch branch-name: We can switch to another branch using this command.

    eg: You are in main branch, want to work on dev-login branch created above. use below command.

    git switch dev-login


5.  git checkout -b branch-name: If we want to create a new branch and switch to that branch. You can use this command.
eg. I want to created branch name: dev and switching to dev branch from current branch: main.


We can observe that new branch (dev) is created and I am in dev branch now.


5. git branch -d branch-name: Used to delete particular branch.

Note: When you're working as team, discuss with other teams members or developer why you want to delete the branch.


6. Branches we created in above steps are created in local repo, there will be only one branch(main) in central repo.

git branch: we can see the branches from local repo.

git branch -r : we can see the branches from central repo.


7.   git branch -m old-name new-name: Use to rename the exiting branch.


8.  Lets us create a login.txt file in dev-login branch and push the code to central repo. follow the steps shown  below.


Adding comments and committing the code. 


Pushing the code to central repo.



8.  Lets us create a signup.txt file in dev-signup branch and push the code to central repo. follow the steps shown  below.


We can commit and push the code from local repo to central repo using below steps:


9. Verify if new branches are created on GitHub. When you open your GitHub account and go to devopsDemo repository ,you can see two new branches are created as below.


10.  We can observe that,login.txt is added in dev-login branch.


      We can observe that,signup.txt is added in dev-signup branch.

We can see the same thing from your terminal locally.






Will continue with Best practices and merging concepts in next session....


Comments

Popular posts from this blog

DevOps session 10: Git basic commands for daily use

DevOps session 6: Linux commands for DevOps team