What is Github?
Github is a website and cloud-based service that helps developers to store and manage their code, as well as track and control changes to their code using Git.
What is Git?
Git is a free and open source version control software that keeps track of changes that you have made to files and directories. So basically …
- Git keeps track of the versions of your file for you.
- Git allows you to move back and forth between different versions.
- Git allows you to compare different versions and see changes between each one. etc.
Now that you know and understand what Github and Git are and what they are used for, first let’s look at how to install git on your local machine(the PC in front of you).
Head over to https://git-scm.com/ to download Git for the operating system platform you’re running and install it. It’s pretty simple, just click on the next button till you’re done.
Git can store configuration settings in three places:
- System Level Configuration(Not often used): Configurations are applied to every user of a single computer. Each user can overwrite the default configuration with their own configuration settings.
- User Level Configuration: Configurations apply to a single user of a PC and it is this type of configuration you’re most often going to use.
- Project Level Configuration: Configurations that apply to a particular project folder.
Here, we’re going to configure Git at the User Level by setting our name and email. There are other things such as the color, text editor, etc. that you can configure, but I want to keep this simple for you as a beginner. Open your terminal or command line and type;
git config — global user.name “Put your name here”
git config — global user.email “Put a valid email address here”
To view the configurations you have done so far type the command:
git config — list
Initializing a Repository
A repository is a place to store code basically. When you want to work with Git, you must, first of all, decide where to put your project on your local machine.
- Create a project folder.
- In your command line or terminal, navigate to that project folder.
- In the root of your project folder, issue the command git init.
The above steps will make your project a git repository and track all the files that “come and go” and changes made inside of the directory only.
Basic or Common Steps In Git
- Make changes
- Add the changes.
- Commit changes to the repository with a message.
Making Your First Commit
Committing in Git means telling Git to track the changes you have made within your project folder after modifying the folder.
- Use git add /file-to-add or git add . command to add all the changes you have made in the project.
- Use git commit -m “message goes here” to commit the changes. Git will now place these changes into permanent memory inside of the repository.
Where Does Github Come Into Play?
Github comes in when you want to host your project online. In doing so, other developers can know what you’re working on and as well collaborate on your project if they find it interesting. Start using Github by creating an account at https://github.com/
Creating an Account
Creating a Repository
After creating an account, head over to the right side of the navigation bar and click on the plus sign. A pop-up menu will appear, click on create a new repository.
Upon clicking on create “new repository”, a new page displays. Here you will need to name your repository( It can either be the same as the project folder on your local machine or a different name. But mostly, it should go with the name of the project folder on your local machine for consistency sake).
Next, you can decide whether to make your repository public (open to all) or private (just for a selected few).
You can either initialize a repository with a README file or not. A README file in your project basically gives a detail description(documentation) of what your project is about. Now click on the “create repository” button.
Pushing Code To Github
This stage involves two steps. It ‘s either you want to create a new one repository and push or push an existing repository. In this tutorial, we will go for the later.
- To link the project folder on your local machine to the repository on Github or for both repositories to be in sync, navigate into your project folder on your local machine and type the command:
git remote add origin “followed by the link to your Github repository”
2. Check if your repository is clean. That is, there are no changes to be added and committed by typing the command: git status
3. Now type the command: git push -u origin master.
- You will be prompted to give your Github username, if you’re not sure, you can head over to Github, on the right side of the navigation bar, click on the profile icon, in the dropdown menu you’ll see signed in as with your username.
- The next prompt will be providing your password(your Github account password).
You should see something similar in the picture below.
Now head over to Github to see the changes you have pushed to the repository online.
You’ve made your first contribution to Github. And this also brings us to the end of this tutorial. If you have any questions, please feel free to ask in the comment section below as well as any suggestions to make this tutorial better and more understandable.