Getting started with Git & GitHub.
Git & GitHub is the most common tools used by developers that helps in managing different versions of your code and collaborate with others.
Table of contents
Building projects are the core parts of being a developer, and Git & GitHub are essential tools everyone uses when building projects with others.
But they can look complicated if you haven't used them before. So I wrote this article to simplify how Git and GitHub works.
What is Git & GitHub?
Git was build in 2005 by Linus Torvalds as an Open-Source software for tracking changes in a distributed version control system. It's source code is freely available for anyone to modify and use, aside from its creators. Open-source projects are built and maintained collectively by different developers from different locations.
It track changes via a distributed version control system. Git can track the state of different versions of your projects while you're developing them, it's distributed because every developer can access their code files from another computer.
While building such projects, every developer requires a way to document or track their code. This makes the work organized, and helps tracking the changes made. This is what Git lets you do. But you also need a place to host the code - which makes controlling each version of the projects easier and faster. This is where GitHub comes in place.
GitHub is platform where Git users store this software-projects. It is also an hosting provider and version control platform users use to collaborate on open source projects and share files i.e.; contributions.
How to start using Git & GitHub.
Step 1 - Install Git
You can download Git here and then select your operating system to download. Follow the necessary installer guide until installation is complete.
Open the command prompt and type git version
to verify that Git was successfully installed.
Step 2 - Creating a GitHub Account.
To create an account on GitHub, you will be asked to provide some personal information like name, confirm your email, set a username and password, and your account should be set up in minutes.
Create an account on GitHub here
Step 3 - Connect your GitHub account to your Git account.
Perform this commands from your terminal.
To set your Git username, type this in your terminal:git config --global user.name "your-username"
To confirm that you have set your Git username correctly, type this:git config --global user.name
You should have "your-username" as the output.
To set your Git email, type this in your terminal:git config --global user.email "youremail@gmail.com"
To confirm that you have set your Git email correctly, type this:git config --global user.email
Your should have "youremail@gmail.com" as the output.
You will be asked to authenticate your GitHub account, so sign in with the same email and username to confirm.
Step 4 - Create and edit your code files locally.
Use any IDE, code editor to edit your code locally. (Recommended: VS Code)
Step 5 - Create a repository on GitHub.
Click the "+" sign at the top right corner to create a new repository. Repositories are like code folders online.
You will be promoted to this page:
Name your repository and give it a description.
Click the "Create repository" button to create the repository. You will be prompted to this page:
Step 6 - Push your local code to GitHub.
You can use the code editor built-in terminal to use Git to push your code to GitHub. Click ctrl
+ shift
+ '
to open the terminal in VS Code.
Input the commands below one after the other in your terminal. Press the Enter
key to proceed after every input.
echo "# sample-code" >> README.md
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin "https://your-repo-link.git"
git push -u origin main
Note that we have git add README.md
in the repository on GitHub. But here we have git add .
, which is to let Git add all our code files instead of the README.md
file which will be created by echo "# sample-code" >> README.md
. So if you have created other files in your local folder, you need to use git add .
to add all files.
Take note that git remote add origin "https://your-repo-link.git"
will contain the link to your own repository and it will have have the name of your GitHub account.
The more you continue using GitHub, the more comfortable you'll get using these commands. The key is to start small and maintain your momentum. It will eventually get easier as you build small projects and host them on GitHub using Git.
Conclusion
If you have finished reading this, you might be feeling overwhelmed about Git and GitHub. Yes it's another big thing you need to learn in tech, but do not feel afraid.
Remember that whenever you start learning something new, at first it can seem like you won't get the hang of it. But after some time and hard work, you'll become more comfortable.
It's the same with Git and GitHub too – if you use it a lot for a while, you will get comfortable with it. Thanks for reading this article. If you enjoyed it, consider sharing it to help other developers.
Happy Learning.