Modify, Merge and Push It…
I’m going through changes 🎶
*This is an optional project assigned by Level Up In Tech*
With this project we will be creating a new branch on our current git repo, modifying an existing bash script file in the new branch, then merge the new branch with the main branch for a push to GitHub.com.
I have been tasked with editing a script I made previously that adds a user to my Linux system. Instead of running the script and having it read my input to create a user, they want it so you can add multiple users by providing usernames as arguments in the command line.
I’ve left two links below that will take you to the start of this project should you want to follow along…
- https://dansantarossa.medium.com/getting-started-with-github-basics-tutorial-b07f2cfe2eaa
- https://dansantarossa.medium.com/bash-script-that-adds-new-user-932fd9a20cb4
Lets get started shall we?
Branching Out
First, I wanna make sure that I am in my main branch with this command…
git status
I can see that I am in my BASH-scripts directory and working on the main branch of my repo. Now lets create a new branch.
There are a couple ways we can do this…
You can create the branch with git branch name_of_branch
Then move to your new branch with git checkout name_of_branch
Or you can simply use git checkout -b branch_name
which will create a new branch and then move you into it. I’ll be using this command…
As you can see I have created a new branch called ‘dev’ and moved right into it. Now I am ready to make changes to my script file. Lets do a quick check to see if my file is there with the ls -l
command…
Modifying The Script
This is an image of my original script…
And this is an image of the modified script, which now allows me to enter users names as arguments…
Lets make sure the changes work…
I’ve made the changes I wanted, so I can commit the change to the repo on the dev branch with this command…
git add useradd1.shgit commit -m "Made first changes to script"
The Merge
Now that I’ve made all my changes, I am ready to merge the ‘dev’ branch with the ‘main’ branch. To do this I’ll need to be back in my main branch…
git checkout main
I am back in my main branch so lets merge the branches…
git merge dev
Now I’m going to push my local repo to my remote repo back at GitHub.com…
git push
I seem to have gotten a really funky looking error when I did this push. I have not seen this before. But, it would also appear that everything made its way over to GitHub perfectly fine…
Lets take a quick look at the actual script content…
Hmm definitely something to look into, but this completes the objectives for this secret section project. Thanks for following along. See ya soon.