Learning Git and GitHub
Hello, World!
I’m undergoing an Application Developement refinery program with TheStartupIntern. through-out this program, I’ll always be provided with resources to study and tasks to perform that will solidify my learning.
You can check out The Startup Intern with their website or on Twitter. Most tech industries absorb thier graduates into thier workspace.
This article is based Learning and working with git and github. I was asked to summarize what I have learnt and the challenges I faced while learning.
WHAT IS GIT?
Git is the most used free and open source version control system. See git as a tool.
Yo, I gat ya!! … you just asked, “what the heck is version control?”
Version control, also known as source control, is the practice of tracking and managing changes to software code. Version control systems are software tools that help software teams manage changes to source code over time.
WHAT IS GITHUB?
Github is a web based interface that uses Git, it is a code hosting platform for version control and collaboration. others include: Gitlab, Bitbucket, Aws Code Commit. Hence, Instead of Github, one can decide to use Gitlab or the rest, But Github is the most used.
COMMON GIT TERMS AND COMMANDS.
- Terminal / Command line : This is an application that runs on your PC where you can run text commands like git commands, navigate around folders, create and change files etc.
- Repository: This refers to a folder like envelope that houses your project. Which can be local or remote.
some commands include:
- git clone: This command is used in the terminal to copy a repository hosted in github into a folder in your local machine.
- git add: This command is used in the terminal to stage changes to git.
- git commit: This command is used in the terminal to save files and changes to files into git.
- git push: This command is used in the terminal to upload git commits to a remote repo hosted in github.
- git pull: This command is used in the terminal to download changes or to download the contents of a remote repository into your local machine. This is the exact opposite of #git push.
LET’S PRACTICE,
from this screenshot,
1 The app opened is a linux terminal, in windows its called command line, its also called terminal in Mac OS.
2 I have navigated to a folder where my html projects stay~/html_css_js this folder houses my html projects, from there, I navigated into an actual html project~Project_3, this is the project I want to push to github.
3 I initialized git using the command ~git init, inside the project folder.
4 Using the git command, ~ git add . , I staged the files inside the project in git, and the next thing is to commit the staged files using the command ~git commit -m “” . The quotation mark holds the commit message, this has to be a descriptive message that tells someone in advance, what was done in the commit.
THUS FAR, We have initialized git in our local repository, we have added and saved our files in the local repo git. BUT, if we happen to lose this local machine, we will lose these codes, WHY? This is because, we are yet to push these codes to a git hosting site like Github, which can then store our repo in the cloud (Clouds? sky? the blue sky? wellll, not that one, call it an advanced storage system, discussion for another day). After we push to github, we can access our repo from anywhere, with any device that can access github.
LET’S PUSH!!!
Get Ezeoke Tochi’s stories in your inbox
Join Medium for free to get updates from this writer.
Firstly , go to github and sign up if you don’t have an account.
Then, Create a new repository by clicking on the green button with text New, The button after Sort . As can be seen in the screenshot below.
on clicking the New button, a page with forms pushes to the screen, you input your desired repo name, a brief description and click on Create repository.
After you’v created the repo, a page similar to the screenshot below pops out to the screen.
Click on SSH, as this is the only method I will be covering in this article.
The next thing to do is To add a remote origin to our already initialized git in our local system. Hence, we head back to the terminal. The instructions can be seen in the previous screenshot, in the part with the title : ..or push an exising repository from the command line , we can just copy those codes and paste on the terminal for accuracy sake.
I copied the ~ git remote add origin.. comand to the terminal, hit enter , there wasn’t an error , so we are cool. I tried to push , then an error came up saying “The current branch master has no upstream branch” .
Then I tried to set an upstream branch with the last command, which also brought forth a an ssh error saying~could not find remote repository.
This is because we have not configured ssh for our remote repo. we need to configure it in order to connect the git in our local repo to the remote repo which is in github. Afterwards, we can then push.
CONFIGURING SSH.
Using the directives given in generate and add ssh_key to github , you will be able to create a new ssh key, add it to github, and also add it to the ~/.ssh folder in your local machine root directory.
Make sure to close and re-open your terminal afterwards, then, navigate to the local repository and run ~ git push — set-upstream origin master . The expected output is as follows:
Go back to your github repo, You should observe changes, your files should have been uploaded to your github.
VOILA!!! ,
I know it wasn’t an easy process for a first timer, it was difficult for me too the first time I did it. With regular practice, you will find it interesting.
OTHERS
I also learnt about git branch, pull requests, git branch merging and of course, Merge Conflict. I also learnt about Undoing actions in git, forking, amending commit messages. etc
But I won’t be going into these in this article.
Finally, I am convinced that the only mistake without a solution while using git is when one deletes the hidden .git in a repo. Anything else can be undone.
THE MAJOR CHALLENGE I FACED WHILE LEARNING GIT AND GITHUB
The major challenge I encountered was when I did everything I had to do correctly, but I still couldn’t push. My brother advised me to close the terminal, reopen it and try pushing again. I did just as he advised and it worked!!!
Secondly, I noticed that its easier and faster to push to github using the HTTPS method, But the SSH method proves to be more secure.
connect to me via linkedin , twitter .
see ya soon!!.




