DEV Community

Cover image for Git for Beginners
adams mercy
adams mercy

Posted on

Git for Beginners

Introduction

As a developer at any level, knowledge of Git is really essential. This tutorial is beginner friendly and covers everything you need to know to get started with Git, Git commands, Git hosting services, etc. as a developer. In this tutorial, we will answer: what is Git? , why Git? , how to use Git, what is version control system and many more.

Version Control

Version control, also known as source control, is the practice of tracking and managing changes to software code. Version control systems are software tools that help software teams manage changes to source code over time. Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members. Examples of version control system are Git, SVN (Apache Subversion), CVS, mercurial, etc.

What is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects. By far, the most widely used modern version control system in the world today is Git. Git has been designed with performance, security and flexibility in mind.

Why Git?

  • Git is good: Git has the functionality, performance, security and flexibility that most teams and individual developers need.

  • Git is a de facto standard: Git is the most broadly adopted tool of its kind. This makes Git attractive for many reasons. The predominance of Git also means that many third party software tools and services are already integrated with Git

  • Git is a quality open source project

Installing Git

Before you start using Git, you have to make it available on your computer. Even if it’s already installed, it’s probably a good idea to update to the latest version. Click here to read more on installing Git and here to set it up.

Configure Git

To ascertain you have Git installed, run “git --version” to see the version. Let’s get your identity set up on git.
The first thing you should do when you install Git is to set your user name and email address. Run the following commands:

[git config --global user.name “your username here”]
[git config --global user.email “your email address here”]

Git commands

Here are the list of some common basic commands. Atlassian listed more basic git commands, see here.

Basic Git commands

Basic Git commands

Basic Git commands

Git hosting services

There are quite a number of Git repository hosting services. Examples are Bitbucket, GitHub, GitLab, and many more. I have used Bitbucket and am using GitHub currently. In the next few paragraph, I will cover GitHub.

GitHub

GitHub is the single largest host for Git repositories, and is the central point of collaboration for millions of developers and projects. A large percentage of all Git repositories are hosted on GitHub, and many open-source projects use it for Git hosting, issue tracking, code review, and other things.

Getting Started with GitHub

Head over to GitHub and create an account and then update your information.

How to use Git and GitHub

  • Go to GitHub, and under Repository tab, click on “New” to create a repository.
  1. Give it a name

  2. Make it public for other to access it / private if you don’t want others to access it

  • After creating the repo, a new page is displayed containing the commands to connect your remote repository with your local repository. Copy the all commands (using an icon displayed at the top of the commands) depending option best suited for you. The first commands is for a project you are just starting on in which you want to manage with git or a project you are working that isn’t managed with git while the second commands is for a project that exist on your local machine which is being managed by git locally only but you want to manage remotely on GitHub.

github

  • Open your project in a code editor and paste in the commands in the terminal (Visual Studio Code editor only)

  • Open and Paste the commands in your command line interface (examples are git bash, command prompt, etc.) and press enter to run the commands. Note: Visual Studio Code has a built-in command line interface. You can also install git bash to use it.

  • After this, your remote repository (GitHub) is connected to your local repository (local machine).

  • Make changes to your code, add those changes (git add .) and commit (git commit –m ‘your message’) and then push (git push) to update the remote repository. The below image shows the state of the remote repository after pushing the local changes.

remote files

Conclusion

There is a lot we can do and achieve with Git and any Git hosting service, like collaborating with other developers on projects, contributing to open source projects, etc.
This tutorial has guided you into what Git is, and has demonstrated how to use Git with GitHub. Always refer back to the commands above to see what they do and their usage. Happy coding and collaboration with developers.

Top comments (0)