Introduction
It's only been two weeks since I enrolled in the LuxDev Data Science, Analytics and AI program yet I've already learnt so much!
One of the first things I've been able to learn is how to take a project from a local folder in my PC and publish it to GitHub using Git and SSH.
For someone who is still building their skills in data and tech,terms like repositories,commits,staging,remotes and SSH keys were new to me at first. Working on my first project helped me understand these commands and also what happens behind the scenes.
So for a start,I decided to document my experience of taking my first GitHub project from a local folder to GitHub using Git and SSH.
What are Git and GitHub?
Interestingly, I learnt that Git and GitHub are not the same thing. This is why understanding what each of them means became a very important step in my project.
Git
Git is a version control system which runs in my PC and helps me keep track of changes made to files in a project.
As I work,I might change my code,update my analysis,add new files or fix mistakes. Git lets me keep track of the changes I make over time instead of having multiple edited copies of the same file. Each saved version is called a commit.
GitHub
GitHub is an online platform where repositories from Git can be stored and shared.
Git does not need to work with GitHub as I can use it in my PC without uploading my project elsewhere.
However, GitHub becomes useful when I want to:
- Keep a back up of my projects online
- Show potential employers what I can do
- Share my work
- Collaborate with others
- Build a portfolio
- Contribute to open-source projects
In a nutshell, this is the journey the local folder in my PC took to reach Github:
Project folder in my PC
`
Track changes with Git
`
Commit changes
`
Push to GitHub
Step 1: Create the Project Files
I first created my project folder in my PC's file explorer and named it Kenya_Health_Records_Analysis.
Then I opened Git Bash and navigated to it using these commands:
cd Desktop
cd Kenya_Health_Records_Analysis
cd(change directory) is a command that tells Git to enter a file or folder in simple terms.
I then proceeded to add a data and README.md file in the project folder:
mkdir data
touch README.md
mkdir(make directory) is used to create a new file or folder from the Git Bash terminal but notice I did not use it to create the README.md file because touch is used to create files with extensions like .md, .py or .ipynb .
I then copied my Kenya_Health_Records.csv dataset and pasted it into the newly created data file in my file explorer.
To confirm this in Git Bash I ran the ls command which lists the contents of a file or folder.
This is what I could see:
ls data
Kenya_Health_Records.csv
Then I went ahead to briefly describe the project in the README.me using the echo command:
echo "# Kenya_Health_Records_Analysis" >README.md
echo " Using Excel to analyze Kenya health records to uncover,trends,patterns and insights in healthcare data." >>README.md
echo prints text while >directs the text into the README.md file however > can replace what is already in the README.md file that is why in the next line I used >> which adds content below what is already there.
To view the full README.md I used the cat command (which displays the contents of a file in the terminal) and ran cat README.md which retrieved:
# Kenya_Health_Records_Analysis
Using Excel to analyze Kenya health records to uncover,trends,patterns and insights in healthcare data.
Step 2: Turning the Folder into a Git Repository
I then ran:
git init
This command initializes a new Git repository and Git begins to manage the project. It also added a new hidden .git file in the project folder.
Step 3: Checking the Status of My Project
One of the most useful Git commands is:
git status
This tells me what Git can see or what is happening inside my repo. At first it told me that both the data and README.md were untracked files meaning that Git had not been told to include them in the project history or to commit.
Step 4: Staging the Files
To stage both files I used:
git add .
The dot tells git to add everything in the current directory.
I then checked the status again using:
git status
The files appeared under the changes to be committed.
Step 5: Creating My First Commit
I then created my first commit:
git commit -m "Add Kenya Health Record Analysis"
The -m allows me to provide a message that explains what I changed.
Hence a commit message can explain what happened at different points in time in the project's history if written clearly.
I then ran:
git log --oneline
This retrieved my unique commit ID and my commit message.
Step 6: Creating a GitHub Repository
After creating the project locally, I went to GitHub and created a new repository and named it the same way I had in my File Explorer:
Kenya_Health_Records_Analysis
This would become an online version of my local Git repository. I also learnt that even though I created the repo and named it the same way,it does not automatically upload my local files.
I still needed to connect my local repo to the GitHub repo and push the changes and this where an SSH Key comes in.
Step 7: Defining an SSH Key
To me, it sounded like such a complex tech term but it was actually just a simple concept.
SSH(Secure Shell) provides a secure way for my PC to connect with my GitHub account.
So after creating the repo on GitHub I was given two link options to connect to it;HTTPS and SSH.
Step 8: Connecting my Local Repository to GitHub
Since I then had both my local Git and GitHub respositories, I needed to connect them using a remote.
A remote is a reference to another repository hosted online.
I then copied the SSH key for my GitHub repository and ran this in Git:
git remote add origin git@github.com:SMumbi5144/Kenya_Health_Analysis.git
origin is the name given to the remote repository.
The SSH address:
git@github.com:SMumbi5144/Kenya_Health_Records_Analysis.git
tells Git where the remote repo is.
To check if the two repos had connected I ran:
git remote -v
Step 9: Pushing the Project to GitHub
Once I had confirmed the two had connected, I pushed my local repo to GitHub by running:
git push -u origin main
git push - tells Git to upload my commits to a remote repository.
origin - refers to the GitHub repository I had added as my remote.
-u - sets an upstream relationship between my local main branch and the remote main branch.
Step 10: Seeing My Project on GitHub
This was the most exciting part of the process. For a beginner like me, it was quite the journey.
I refreshed my GitHub and I could then see my local project files online.
I could therefore view the project online,share it with others and continue working on it.
What I learnt to Avoid
We all make mistakes as we learn and this project was no exception.
Therefore, in order to successfully upload my local files to my GitHub repository I learnt that I should:
- Not forget to initialize Git using
git init. - Not forget to stage files using
git add .else any changes I make will not be part of my next commit. - Never assume commit means upload, to send to GitHub I ought to use
git push. - Avoid using unclear commit messages since they will not help me understand the project history easily.
Conclusion
My first project taught me more than just a few commands. It taught me patience and the importance of paying attention to detail and being systematic since a command will only work efficiently if the correct command is used. These are very important qualities for a data professional to develop so as to enhance the quality of their work.
I also learnt some cool concepts such as how a version control system works, how an SSH Key can connect my PC to GitHub and how I can manage and share my projects.
As I continue developing my skills at and outside LuxDev Academy, GitHub will help me document my projects and build a portfolio that shows what I can do.
This first project was the beginning of my journey towards becoming a better data professional.
Top comments (0)