Git and GitHub are two technologies that every developer should learn, irrespective of their field, you might think that these two terms are the same thing – but they're different. Let's see the difference between these two terms.
What is Git?
Git is a distributed version control system (VCS) that maintains a history of changes to files for reference and rolls back a change. It is software for tracking changes in any set of files, usually used for coordinating work among programmers who are collaborating on the same source code, and widely used, released under GNU GPL v2 license.
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git can:
- track changes in file
- store multiple versions of the same file
- cancel changes previously made
- record who made changes and when
What is GitHub?
GitHub, Inc., is an Internet hosting service for software development and version control using Git. It provides the distributed version control of Git plus access control, bug tracking, software feature requests, task management, continuous integration, and wikis for every project. It is commonly used to host open-source software development projects.
Installing and Setting-up Git
Download GitHub from the website, using the command line is better for cross-platform transformation because command lines are the same for Mac-OS, Linux, and Windows. See for other OS systems installation on website.
Git installation on Ubuntu Linux
$ sudo apt install git
Configuration of Git
To start working with Git you need to specify the user name and e-mail. This is important because every Git commit uses this information and that will be used to synchronize the local repository with your GitHub repository:
$ git config --global user.the name "John Woe"
$ git config --global user.email johnwoe@example.com
If you want to use a different text editor, such as Vim, you can do the following:
$ git config --global core.editor vim
Your default branch name
By default, Git will create a branch called master when you create a new repository with git init
. From Git version 2.28 onwards, you can set a different name for the initial branch.
To set main as the default branch name do:
$ git config --global init.defaultBranch main
If you want to check your configuration settings, you can use the git config --list
command to list all the settings:
$ git config --list
user.name=John Woe
user.email=johnwoe@example.com
core.editor=vim
init.defaultbranch=main
All these git settings are stored in the .gitconfig
file in the user's home directory. Now you can edit using git config --global --edit
will open the ~/.gitconfig
file in a text editor as below:
[user]
name = John Woe
email = johnwoe@example.com
[core]
editor = vim
[init]
defaultBranch = main
We can also configure git, creating a .gitconfig
file in under the user's home directory and pasting the above settings.
If you want more details see First-Time Git Setup.
Initializing Git repository
There are two ways to initialize a repository:
- You can take a local directory that is currently not under version control, and turn it into a Git repository.
- You can clone an existing Git repository from elsewhere (Github/Gitlab).
In either case, you end up with a Git repository on your local machine, ready for work.
Initializing a Repository in an Existing Directory
You first need to create the project’s directory. After that navigate to the project's directory, it's depending on which system you’re running:
for Linux:
$ cd /home/user/my_project
for macOS:
$ cd /Users/user/my_project
for Windows:
$ cd C:/Users/user/my_project
and type: $ git init
as below:
git init my_project
Initialized empty Git repository in /home/user/Desktop/my_project/.git/
This creates a new subdirectory named .git that contains all of your necessary repository files.
Cloning an Existing Repository
If you want to get a copy of an existing Git repository:
You clone a repository with git clone
, for example, if you want to clone the Git library called libgit2, you can do so like this:
$ git clone https://github.com/libgit2/libgit2
That creates a directory named libgit2, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version.
Thanks for reading, stay tuned.