Hey there looking for a GIT tutorial which doesn’t make you scratch your head? Here’s the beginner’s guide to GIT. So let’s get our hands dirty with git.
What is Git?
GIT simply acts as a time machine for your code in technical terms “Git is a distributed version control system for tracking changes in source code during software development.”
It takes series of snapshots of your project. With Git, every time you commit (save the state of your project) Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. So that you may go back later if required.
So let’s begin with downloading Git on your computer
Here’s the link to download Git according to your Operating System:
Git comes with built-in GUI tools ( git-gui, gitk), but there are several third-party tools for users looking for a…
After downloading, follow the steps mentioned here for installing GIT on your Desktop.
On the website you will find an E-book (ProGit) which covers detailed explanation of everything about git.
Here’s the link to the book:
The entire Pro Git book, written by Scott Chacon and Ben Straub and published by Apress, is available here. All content…
If you prefer videos over text based tutorials, than here’s the link for videos:
So let’s begin with GIT
Note: This article is meant to get you started with Git and GitHub for the first time, so sometimes, I have mentioned the most basic or most used version of a command so that users would easily understand it and get started.
Let’s get started…
After installation if you want to know which version of git is installed on your desktop just type the following command :
it will show the current version of GIT installed on your desktop
After Git is successfully installed on your desktop, set your username and email address
git config --global user.name "some user name"
git config --global user.email firstname.lastname@example.org
For further commands, we may need a Folder
So at a convenient location on your computer, create a folder named “git_test” (You can also name it according to your preference).
Open this git_test folder and create a new file. You can create any file but I’m creating an HTML file so that the guide could help beginner web developers.
I’ve created an index.html file in this folder (index.html is simply your homepage/first page you visit on website) add some basic HTML code to the file.
For using the GIT commands first open the git_test folder in your command prompt window/terminal.
To use Git in a folder we would first need to initialize a GIT repository inside the folder( A repository is basically a storage location, similar to a folder)
For Initializing the folder as a git repository :
This command creates a Git repository. This is required for using further Git commands.
Checking your git repository status:
It will check the git repository status. The details of files inside it, changes that need to be committed (committing is basically saving the changes) and details of branch we’re working on.
Telling GIT about updates to files or new files:
git add .
It basically tells git about updates in your file or about new files added in current folder. Contrary to it’s name it doesn’t add files to your repository.
Let’s check the status of our folder now.
To commit/save our updated files on git repository :
git commit –m "Some Message"
This command records changes to our git repository. The “snapshot” of your repository is taken here.
As a developer it is always suggested to keep the message meaningful (and not something like “Updated some code”).
If you want to check details of previous commits:
This command will show full details of previous commits.
In case you want to see fewer details then add the — oneline option.
git log --oneline
Well now that you have made a GIT repository, let’s create an online repository on GitHub (You can also do this on BitBucket)
- Head to GitHub and in the upper-right corner of any page, click + and then click New repository
- Type a name for your repository
- Write an optional (message) or description if you want. You can make the repository either public or private. Public repositories are visible to everyone on Github, while private repositories are only visible to you.
- We would skip this optional step as we will be importing an existing GIT repository, so let’s click on “Create repository”.
Since we will be pushing contents from an existing repository so we will use the following commands
- Connect your local git repository to remote repository:
Git remote add origin <repository URL>
2. Set Branch:
git branch -M main
A branch in git is similar to the branch of a tree, we could create multiple branches of a repository so that many people can work on the same code at the same time without getting confused.
3. Push your commits to online repository:
git push –u origin main
Here we push(upload) all the content from our local repository to the remote repository on Github.
Reference links :
Git is a free and open source distributed version control system designed to handle everything from small to very large…
Creating a new repository
You can create a new repository on your personal account or any organization where you have sufficient permissions. In…
Link to the Github Repository created in this article:
Thank you for reading my article, I hope you enjoyed it and learnt something from it. I would be more than happy if you send feedback or suggestions.
You can find me on: