DEV Community

MERCY MUMBI WAHOME
MERCY MUMBI WAHOME

Posted on Edited on

Understanding the Git Workflow: Working Directory, Staging, Commit and Push

Beginner friendly explanation of Git and GitHub: Kenya Hospital Health Records

When I started learning Git and GitHub, I was completely new to them and the terms used like repository. I slowly began to understand how these tools work together. Git helps track and manage changes to a project while GitHub allows us to store the project online.
In this project, I applied what I learned by creating Kenya Hospital Health Records and moved it from my local computer to GitHub. So this article explains my journey from the start to successfully uploading my project to GitHub, explaining each step in a simple way.

1.Understanding the Git Workflow

I learnt the basics of a G it workflow: working directory where I create and edit files, staging where I prepare selected changes, commit to save them as a checkpoint and pushing to send the work from my computer to GitHub.

2.Connecting Git to GitHub Using SSH

I first confirmed that Git was installed on my computer, then checked for an existing SSH key and found mine

3.Creating the project locally

I created a folder named Kenya Hospital Health Records and opened it in GitHub, then created the project files that would make my hospital records project. I then checked the folder to confirm the files have been created successfully. This gave me the basic project structure that I would later track using Git.

4.Initializing Git and Checking the Project

Now that my files were ready, I needed to introduce Git to the project by creating a local repository that would allow me to track changes to my files. Then I checked the Git status to see how it viewed the files. They appeared as untracked.

Next, I staged the files which tells Git which changes I want to include in my next commit. I then created my first commit, the initial commit. A commit is like a checkpoint that saves the current state of my project in Git's history.

5.Creating the GitHub Repository

After creating and committing my project locally, I needed an online place to store it, so I created a new repository on GitHub and gave it a name similar to my local project. I kept the repository empty because the project and its initial commit were already on my computer which will allow me to connect to the existing local project to the new GitHub repository

6.Connecting the Local Project to GitHub

I then connected my local Git repository to the GitHub repository using the SSH address I had copied from GitHub. I gave this remote connection the name** origin**, the standard name for the main remote repository. I checked the remote connection to confirm that the GitHub SSH address had been saved correctly for both fetching and pushing.

7.Setting the main branch

The next step was to make sure my project used the main branch. A branch is a separate line of development where changes to a project can be managed.

8.Pushing the project to GitHub

I used the push command to send my committed files from the local repository to the GitHub repository. The command also connected my local main branch with the remote main branch so that Git would know where to send future updates. Git confirmed the main branch was successfully set up to track origin. This was an important moment in my learning because I could see the work I had created and saved locally could finally appear online.

After the push was done, I opened my GitHub repository and I could see my project files online confirming that the local project had been successfully uploaded.

Conclusion

This project helped me understand Git and GitHub by actually using them. I learned how to create a local project, track it with Git, connect it securely to GitHub using SSH and upload online.
The workflow:** Working Directory > Staging > Commit > Push > GitHub** may seem complicated at first but once each stage is understood, it becomes easier to follow.

Top comments (0)