Advance Git & GitHub for DevOps Engineers
Table of contents
- Add a text file called version01.txt inside the Devops/Git/ with “This is the first feature of our application” written inside. This should be in a branch coming from master, [hint try git checkout -b dev], switch to dev branch ( Make sure your commit message will reflect as "Added new feature").
- Add a new commit in dev branch after adding the below-mentioned content in Devops/Git/version01.txt: While writing the file make sure you write these lines
- Demonstrate the concept of branches with 2 or more branches with a screenshot
- add some changes to dev branch and merge that branch in master
Add a text file called version01.txt inside the Devops/Git/ with “This is the first feature of our application” written inside. This should be in a branch coming from master
, [hint try git checkout -b dev
], switch to dev
branch ( Make sure your commit message will reflect as "Added new feature").
- To Add a file in DevOps/Git/ directory,
touch Devops/Git/Version01.txt
- Now add Content to it,
This is first feature of our application
- Add and commit the file,
sudo git add Version01.txt
sudo git commit -m "Added new feature"
- Now, check out to new branch "Dev"
sudo git branch Dev
sudo git checkout Dev
- Now, add some more content to it,
This is the bug fix in development branch
- Add and commit changes in the Dev branch,
sudo git add Version01.txt
sudo git commit -m "Added feature2 in development branch"
Add a new commit in dev
branch after adding the below-mentioned content in Devops/Git/version01.txt: While writing the file make sure you write these lines
1st line>> This is the bug fix in the development branch
Commit this with the message “ Added feature2 in development branch”
2nd line>> This is gadbad code
Commit this with the message “ Added feature3 in the development branch
3rd line>> This feature will gadbad everything from now.
Commit with the message “ Added feature4 in the development branch
Restore the file to a previous version where the content should be “This is the bug fix in the development branch” [Hint use git revert or reset according to your knowledge]
Now, we have to get rid of the last two lines, to recover use the below steps,
- To Recover to the previous version,
sudo git log
copy commit id which you want to revert and use the below command
sudo git revert a53c29
You have successfully reverted to the previous version of your code
Demonstrate the concept of branches with 2 or more branches with a screenshot
Git branching is used to take a clone of a code and implement new ideas and bug fixes without disturbing the main branch.
- To create a new branch,
sudo git branch Develop
To check whether the branch is created or not,
sudo git branch
- To switch between branches
sudo git checkout <branch_name>
In our case, we have a branch named "Develop" so,
sudo git checkout Develop
add some changes to dev
branch and merge that branch in master
- In Develop branch we have this content in the "Version01.txt" file,
- Switch to the main branch and merge the changes of Develop branch,
Before merging in the Version01.txt file
We have only one line of code in the file
After merging the code from Develop branch
- To merge code from another branch, we use
sudo git merge <branch_name>
Here, we can see Versio01.txt file has changes and there is 2++ indicates there is 2 insertions (+)
Now, cat Version01.txt to verfiy changes.
Subscribe to my newsletter
Read articles from Neha Bisen directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by