Lately, I have received emails on how to use git and Github. Most questions were from complete beginners, for that reason in this post we are going to learn how to use git and Github then lastly I’ll show you how to host your sites on Github for free. This is an introduction to git and github.
Before we get started you should have:
- Installed git: You can install it for windows from; here and other OS here
- A created account with GitHub: Click here if you haven’t registered yet.
What is git?
Git is a version control system that tracks changes to files, for instance, if you make a change on a file, git will help you know exactly what changed, who changed it and why it was changed. this is also important as it is easy to roll back to the previous version.
The following examples will be using the Command-line Interface(CLI)/Terminal.
Is git the same as Github?
No, Github and git are different. Many people understandably confuse the two. GitHub is a website for hosting projects that use git.
Common Git Commands
The following are some of the common commands you will always use, feel free to google and learn more about them. This post just tries to give you an insight and is not a complete lesson on git you can get the whole git glossary here. I tried to list them in the order they will be used.
This will create a new repository in the current directory. You can initialize a repository in any folder you would like to track files in.
git clone <remote origin URL>
In case you don’t want to create your own repository, you can clone an already existing repo. It will download the repo from the internet into your current working directory. most times a folder with the same name as the online repo will be created.
This will print some basic information, such as which files have recently been modified. or no changes:
symons@symons-macbookair:~/Desktop/Projects/omborisymons/symons_project$ git status On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean
Next command is:
git add <files>
This command will mark files changed as staged or ready to be committed. You can use git add –all to add everything that has changed, Note: Before using git add –all Ensure only what you want to commit was changed, use git status
Now that the files are ready to commit the next thing is to commit them.
This will open your default command-line text editor and ask you to type in a commit message. As soon as you save and quit the commit will be saved locally.
Commit message is important as it will help others understand what changed and why it was changed. Find out how to write good commit messages here
You can use the
-m flag as a shortcut to writing a commit message example:
git commit -m “Add a footer”
Now we have our commits locally, if we want others to see what we have done we need to push them somewhere like Github.
git push origin <branch-name> //eg git push origin master
Now your teammates can pull and see your changes on their local machines:
git pull origin master
This will fetch and merge your version to their version.
And that was introduction to git and github part 1
Now you have a basic understanding of git, take a break then read part 2 of this post where we will learn about branching and do a real-life practical example host our website on Github. Don’t forget to leave a comment below.