DevOps(Day-14): How to Use Git and GitHub
Differences between Git and GitHub
Git is a version control system that manages and keeps track of your code. GitHub, on the other hand, is a service that let you host, share, and manage your code files on the internet.
GitHub uses Git underneath, and lets you manage your Git repositories or folders easily on its platform.
So Git is the actual version control system and GitHub is the platform where you host your code.
How to Start Using Git and GitHub
Step 1 — Install Git
Git comes preinstalled in some Macs and Linux-based systems, but you can always check if you have Git installed in your machine by typing git version
in your terminal. You can use the Command Prompt to do this.

As you can see above, I have Git version 2.31.1 installed on my Windows computer. If you don’t have Git installed in your computer, you won’t get a version.
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 — Create a GitHub Account.

To create an account on GitHub, you will be asked for 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.com here.
Step 3 — Connect your GitHub account to your Git account.
You’ll do this from your terminal.
To set your Git username, type this in your terminal:
To confirm that you have set your Git username correctly, type this:

To set your Git email, type this in your terminal:

Step 4 — Create and edit your code files locally

Step 5 — Create a repository on GitHub
Click the + sign at the top right corner to create a new repository. Repositories are like your code folders online.
You will be prompted to this page:
Name your repository and give it a description (this is optional).
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 VSCode.
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://github.com/segunajibola/sample-code.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://github.com/segunajibola/sample-code.git
will contain the link to your own repository and it will have have the name of your GitHub account.
Common Git Commands to Know
They are many Git commands you can use in the terminal, and that can get overwhelming. So I’d suggest focusing on some of the most popular ones first.
Here they are:
git init
lets you initialize Git in your folder.
git add Readme.md
lets you add the Readme file, while git add .
lets you add all files in the present folder.
git commit
stores the added files. Use -m
for message followed by the actual message.
git branch
creates a new branch which is a new version of the repository as it appears when added, and -M
to move the name to main
.
git remote add origin
finally connects the local folder to the repository on GitHub. It is followed by the repository's link.
git push -u origin main
pushes the code to GitHub. The -u
flag creates a tracking reference for the branch, and origin main
puts the code in the main
branch.
Those are some of the main commands you’ll use all the time. This is a beginner and non-technical guide to help you get started using Git and GitHub, so we won’t go into too much more detail here.
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.
If you find it hard to use the terminal to navigate between folders, spend some time to practice with it. Again, it gets easier with time and use.
How to Customize Your GitHub Profile
Customizing your GitHub profile README helps you stand out from random GitHub users.
The README.md file helps you describe your GitHub profile, and you can use it to show what you’re currently learning along with your skills and contributions.
The GitHub README.md uses markdown to format its content. It has an easy-to-learn syntax.
Here is a simple guide to create and customize your GitHub account.
Comments
Post a Comment