Contributing a new project to Github

Contributing a new project to Github

Welcome to Weiping’s Channel! As a powerful and popular code hosting platform for version control and collaboration, It is widely used in software developing companies and becomes one of the must-have skills for us software engineers.

Here I am going to talk about how to create a new repository in GitHub when starting a new project, and how to update the repository with Git. Here, the new project is a simple task, which is to create a BASH script to add users in the CentOS 8 server. Also I will share the BASH scripts in the end of this post.

Step 1 Create a new repository in Github

Login to?https://github.com?and click the “+” and choose “New repository”. Follow the guideline in the official Github website to create a repo:?https://docs.github.com/en/get-started/quickstart/create-a-repo.

No alt text provided for this image

The newly created repo will display on the home page.

Click the repo we just created.

No alt text provided for this image

You will see some tips about how to create a local repo in your computer (we call it “local”, compared to the repo in Github, which we called “remote”) on the page like below. Follow the first one “create a new repository…” as this is a new project.

No alt text provided for this image

Now we need to create a working directory in our local environment.

The new project is to add a user to the CentOS 8 server. So now I login to a CentOS 8 system and create a working directory “test” under my home directory and create a BASH script usersadd.sh in (please see the details of the script below).

After the work is ready to be pushed to remote in Github where people can see it from the Github website, run the commands on the Github page in the working directory.

No alt text provided for this image
No alt text provided for this image

Now the files usersadd.sh and README.md created in the local machine are pushed to the remote master branch.

No alt text provided for this image

Step 2 Update the repository

Now there is new requirement asking to update the feature of the project that Based on the new requirement that multiple users need to be added to the CenOS 8 system at a time. We need to update the script usersadd.sh to fulfill this requirement. (Please see the details of the script below)

First we check the status of our current branch and make sure it is up to date with the remote one.

Then from the master branch, we create a new branch using

$ git checkout -b <new branch>

After that, we update the BASH script and the README.md in the new branch dev.

No alt text provided for this image
No alt text provided for this image

After the changes are made and everything is verified working fine, we need to merge the changes back to the local master branch by checking out back to the master branch and merge the dev branch.

$ git checkout master

$ git merge dev

No alt text provided for this image

After merging the dev branch into the master branch, use git push to push the changes we just made to the remote master branch in Github.

No alt text provided for this image
No alt text provided for this image

Check the status of the local master branch again, it is up to date with the remote master branch in Github.

No alt text provided for this image

In Github, it shows the updated repo and the commit messages.

No alt text provided for this image

Appendix The project requirement and the BASH script

The project require

  • You will be prompted to input the user’s Name.
  • The new user home directory will be added.
  • The script will determine if the user already exists. If so, output a message stating “user found”. If not, the script will verify whether the new user home directory is added.

No alt text provided for this image

Run the script:

When the user exists:

No alt text provided for this image

When the user does not exist and is ready to be added:

No alt text provided for this image

The new requirement after the repo is created:

  • Modify your script so that you can add multiple users by providing usernames as arguments.

No alt text provided for this image

No new users to be added:

No alt text provided for this image

2 new users to be added:

No alt text provided for this image

Above is a simple Git project creation and update with BASH scripts about adding new users in a Linux system attach. Hope you enjoy the reading! See you next time.

John White

Cloud DevSecOps Engineer ? Joyful Problem Solver

2 年

Great article, Weiping!

回复
Steven Roscoe

Security Analyst @ EWTN

2 年

Nice article!

回复
Katoria H.

Platform Engineering Leader @ Comcast | Advisor | DevOps | AWS Community Builder | Docker Captain | Cloud Engineering | Cloud Resiliency | Cloud Automation & Security

2 年

Looks good!

要查看或添加评论,请登录

Weiping Zhang的更多文章

社区洞察

其他会员也浏览了