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 10: Git basic commands for daily use

 


Create new Repo on GitHub:

1.Go to your GitHub account and on the header ,click on "+" icon ,Then click on New repository.



2. Provide your new Repo name ,Select the public option if you want to show your work with every one. 

If you want to show the content in repo to specific users ,then select private.

Then click on create repository button at the bottom.



3. Once repository is created, we are navigated to repo dashboard page.


4.  Create a sample README file by clicking on below text in screenshot. 


Then go down and click on commit change button.


COMMANDS:

1. git init:  As a first step we need to create a local empty repo.



2. git clone:  First time when we want to get the code from GitHub repo, we use clone command.

    Go to your GitHub repo you want to clone and copy the SSH link.



Then use git clone [link copied from above].



3. git branch a : This commands will display all branches present for that GitHub repo.

    Before that, once you cloned the latest code you can move into folder ,created with your repo        name using - cd folder name


    

4.  git branch --show-current: Useful to check on which branch you are working.




5.  Add file to local repo and check the status is git status command


Here untracked file are nothing but created for first time but not pushed to staging state.

6. Use  git add . or git add [filepath] to track the files which are newly added or updated.

git add .  : If you want to push all the code to repo at once we can use this command.

git add [filepath] : When you want to push only specific files instead of  files ,we can use this                 command.


7. Git commit :  To save the files and you want to push them to GitHub repo, then we can use command as below. 




8. Git push: to transfer your code from local repo to GitHub repo, we use PUSH command. 



9. you can see the changes are updated in GitHub repo.



 10. Update the read me file from GitHub repo as below and then commit the code.  



11. Then go to your local repository to get the latest code. Use git pull command to get get latest code.


You can see the file using CAT command.



12. git log: If we want to check the recent code commit ,then we can use this command.



To check what are updates in the commit ,we can go to GitHub repo you are working on and the navigate to 
 https://github.com/NAVEENINTEL/devopsDemo/commit/commit-link

Copy and paste the commit-id from above logs and click enter. We can see the changes made on that repo.



Next session will be on Git Branches.....

Comments

Popular posts from this blog

DevOps session 7: Source Code Management/ Version control systems (GIT) || Setup Git on ubuntu

DevOps session 11: Git branching & best practices