Installing and using Git and GitHub on Ubuntu Linux: A beginner's guide

GitHub is a treasure trove of some of the world's best projects, built by the contributions of developers all across the globe. This simple, yet extremely powerful platform helps every individual interested in building or developing something big to contribute and get recognized in the open-source community.

This tutorial is a quick setup guide for installing Git and using GitHub and how to perform its various functions of creating a repository locally, connecting this repo to the remote host that contains your project (where everyone can see), committing the changes and finally pushing all the content in the local system to GitHub.

Please note that this tutorial assumes that you have a basic knowledge of the terms used in Git such as push, pull requests, commit, repository, etc. It also requires you to register to GitHub here and make a note of your GitHub username. So let's begin:

1 Installing Git for Linux

Download and install Git for Linux:

sudo apt install git

The above command is for Ubuntu and works on all Recent Ubuntu versions, tested from Ubuntu 16.04 to Ubuntu 22.04, and it's likely to work the same way on future versions.

2 Configuring GitHub

Once the installation has successfully completed, the next thing to do is to set up the configuration details of the GitHub user. To do this use the following two commands by replacing "user_name" with your GitHub username and replacing "email_id" with your email-id you used to create your GitHub account.

git config --global "user_name"
git config --global "email_id"

The following image shows an example of my configuration with my "user_name" being "akshaypai" and my "email_id" being "[email protected]"

Git Config

3 Creating a local repository

Create a folder on your system. This will serve as a local repository which will later be pushed onto the GitHub website. Use the following command:

git init Mytest

If the repository is created successfully, then you will get the following line:

Initialized empty Git repository in /home/akshay/Mytest/.git/

This line may vary depending on your system.

So here, Mytest is the folder that is created and "init" makes the folder a GitHub repository. Change the directory to this newly created folder:

cd Mytest

4 Create a README file to describe the repository

Now create a README file and enter some text like "this is a git setup on Linux". The README file is generally used to describe what the repository contains or what the project is all about. Example:

gedit README

You can use any other text editors. I use gedit. The content of the README file will be:

This is a git repo

5 Adding repository files to an index

This is an important step. Here we add everything that need to be pushed onto the website into an index. These things might be the text files or programs that you might add for the first time into the repository or it could be adding a file that already exists but with some changes (a newer version/updated version).

Here we already have the README file. So, let's create another file that contains a simple C program and call it sample.c. The contents of it will be:

int main()
printf("hello world");
return 0;

So, now that we have 2 files

README and sample.c

add it to the index by using the following 2 commands:

git add README
git add sample.c

Note that the "git add" command can be used to add any number of files and folders to the index. Here, when I say index, what I am referring to is a buffer like space that stores the files/folders that have to be added into the Git repository.

6 Committing changes made to the index

Once all the files are added, we can commit it. This means that we have finalized what additions and/or changes have to be made and they are now ready to be uploaded to our repository. Use the command :

git commit -m "some_message"

"some_message" in the above command can be any simple message like "my first commit" or "edit in readme", etc.

7 Creating a repository on GitHub

Create a repository on GitHub. Notice that the name of the repository should be the same as the repository's on the local system. In this case, it will be "Mytest". To do this login to your account on Then click on the "plus(+)" symbol at the top right corner of the page and select "create new repository". Fill the details as shown in the image below and click on "create repository" button.

Creating a repository on GitHub

Once this is created, we can push the contents of the local repository onto the GitHub repository in your profile. Connect to the repository on GitHub using the command:

Important Note: Make sure you replace 'user_name' and 'Mytest' in the path with your Github username and folder before running the command!

git remote add origin

8 Pushing files from a local repository to a GitHub repository

The final step is to push the local repository contents into the remote host repository (GitHub), by using the command:

git push origin master

Enter the login credentials [user_name and password].

The following image shows the procedure from step 5 to step 8

Pushing files in local repository to GitHub repository

So this adds all the contents of the 'Mytest' folder (my local repository) to GitHub. For subsequent projects or for creating repositories, you can start off with step 3 directly. Finally, if you log in to your GitHub account and click on your Mytest repository, you can see that the 2 files README and sample.c have been uploaded and are visible to all as shown in the following image.

Content uploaded to Github

Share this page:

128 Comment(s)

Add comment

Please register in our forum first to comment.


By: nwnpallewela at: 2015-02-19 05:24:43

This is great... Thanks for your help :)


By: Feragon at: 2015-04-01 15:37:52

Thanks a LOT!!! Very usefull tuto, and very simple. Thanks again.

By: Deepak Kanavikar at: 2015-04-03 18:06:59

This was precisely what i was looking for... Thanks

By: ashutoshh at: 2015-04-13 04:01:17

thanks a lot

By: honlulu at: 2015-04-15 15:51:50

<h1> very helpful xD Thanks a lot </h1>

By: karan at: 2015-05-11 13:03:31

awesome , thank you

By: Chris at: 2015-05-21 08:42:31

Thank you!

By: auchomage at: 2015-06-05 12:58:16

Thanks for this, it is very clear and helpful.

By: vartika at: 2015-07-16 07:13:07

thank you very much for such a clear and concise tutorial! :)

By: AlFoNsO_O_BEST at: 2022-11-11 13:28:06

is a question possible?

after following the guide does everything work? and if so are you daughter of god for making it work?

By: saurabh at: 2015-08-04 12:56:46

Thanks a lot, really very helpful.

By: Rajani at: 2015-08-17 05:34:44

Very helpful. Thank you very much

By: Kishor at: 2015-08-24 06:49:59


By: goldie at: 2015-09-18 09:08:06

awesome... spent so much time but did not get... but with this tutorial... its really easy.. thank u

By: jeet at: 2015-10-01 05:51:01

awesome easy to understand.....

By: swayne at: 2015-10-15 20:48:52

Very nice, concise beginners tutorial!  FYI... one little typo found... In section 5: git add smaple.c  (should be "sample.c")

By: maitreyee at: 2015-11-03 06:03:47

Extremely helpful. I followed it step by step and I got exactly what I wanted


By: Jerry at: 2015-12-04 08:22:32


By: neil at: 2015-12-09 07:05:10


By: Bilal at: 2015-12-09 12:21:37

Thank you so much

By: Bilal at: 2015-12-09 12:26:25

one more thing friends, suppose someone get any issue in  git push origin master

please use this git push origin master --force its work for me

By: jorge8979787 at: 2016-01-21 22:01:40


By: Luna Das at: 2016-02-05 08:09:57

nice article that what I was looking for :)

By: Murat Ersin at: 2016-02-14 16:51:32

It's work so great.Thanks for this tutorial.

By: om at: 2016-03-02 04:37:53

This is very cool tuto, love it.

By: Chichio at: 2016-03-16 10:38:10

Thanks. But i must run command: git pull origin master before git push origin masterI'm newbie

By: Chatchai Saratakij at: 2016-04-06 15:42:32

Wow, Thank you^_^

By: luan at: 2016-04-07 22:48:23

how to integrate postgresql to github? 

By: Shradha at: 2016-04-11 11:26:38

Thank you so much..This is the most precisely explained tutorial...:)

By: Kautsya Kanu at: 2016-04-20 07:14:09

Best Tutorial that I found.. Thanks a lot!! :) You are really great..

By: yohannes at: 2016-04-20 07:57:22

Thanks that will help for starters like me.


By: Jacob at: 2016-04-28 15:08:57

 This was great, but I initially received a error when I tried the git push origin master. 

The error looks something like this: fatal: unable to access '': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

I believe it is a certificate trust issue, but the fix for me was to enter the following commands (ref:

export GIT_SSL_NO_VERIFY=1 #or git config --global http.sslverify falseAfterwards, I am presented with an option to provide my username and password.   

By: Shashikant Singh at: 2016-05-25 09:59:49

Very good tutorial . Very clean explaination. 

By: Devashish Kumar Jaiswal at: 2016-06-28 11:01:07

Thanks a lot..This is very helpful for everyone

By: Tingu at: 2016-08-06 05:24:54

Nice One Article


By: Tingu at: 2016-08-06 05:26:04

 Masaalla article

By: Zakki at: 2016-08-07 13:54:24

Excellent tuto!

By: Graham Newman at: 2016-08-29 15:14:45

Brilliant - many thanks!

By: Ravi Kumar at: 2016-09-05 06:57:45

That's great...Thankyou sir

By: Ishadi at: 2016-09-06 23:54:53

Thanks a lot!

By: subhajyoti at: 2016-09-15 20:18:23

too good

By: Nisal at: 2016-09-21 10:33:47

This is great... Thanks for your help :)

By: Kevin at: 2016-09-24 20:31:47

That's amazing. The best hands on beginner's guide to git. It isn't much of a big deal. Thanks

By: Nikhil Chavda at: 2016-09-25 07:44:03

this tutorial is very usefull for me thank you so much.

By: ahahah at: 2016-10-01 09:21:02

This was soooo helpfull. Thank you soooo much. :))

By: Victor at: 2016-10-11 17:12:18

Thanks for this , I never thought it was so simple, you helpme so much

By: WRONG! at: 2016-10-15 01:21:21

remote add orgin, not add remote origin

By: Irishologram at: 2016-10-26 12:02:34

I just followed this tutorial and create a new github repository, thank you!

By: KC at: 2016-11-25 20:13:05

Thank You! This has been of real help.

By: murali at: 2016-12-05 15:56:47

Thanks for the usefull information....

By: Shrikrishna at: 2016-12-09 15:05:39

Thanks mate exellent article.

By: Eslam Ezzatneshan at: 2016-12-13 10:34:49


Thanks for this helpful article.

I am trying to install the following open-source package on my virtual-box Ubuntu: be honest, I am almost new in Ubuntu and don't know so much about git etc.Could you please help me what should I do step-by-step to install that package? Really appreciate your time. Cheers


By: Shivam at: 2016-12-20 03:14:33

This is simply helpful.. Can you also cover for rest ??

By: nullbyte at: 2016-12-25 17:45:58

Thanks a lot.

By: annie at: 2016-12-26 16:05:00

Too good!

By: Sagar PAtil at: 2017-01-06 04:36:15

Great man cool article. Very easy and clear steps provided.

By: Zachary at: 2017-01-09 01:09:04

Basic but very important! Great!

By: Alok Patra at: 2017-01-09 18:33:54

Great detailed explanation. Helped a lot. Thanks

By: martineskobg at: 2017-01-11 14:33:03

Cool Thanks !! :)

By: p81061473525 at: 2017-01-28 15:13:25

This is great...

By: Jona at: 2017-02-06 04:50:02

SO EASY!!!!!!

By: Antz411 at: 2017-03-01 19:28:56

Excellent work!

By: Umer at: 2017-03-27 18:53:12

Many thanks for this wonderful how-to...cheers :)

By: Manjesh at: 2017-04-03 15:29:48

Dude, Your Tutorials are Awesome .

By: Ajay at: 2017-06-12 07:06:01


Steps is fine but if some one want to add all directory  can use

git add .


before doing this change mode of file if required



By: Wayne B at: 2017-06-22 19:09:55

Hello, very easy and simple instructions for us noobs. Thank You very much for this simple and easy to understand tutorial!

By: vishnu at: 2017-06-23 06:09:59

Thanks very useful 

By: anvesh at: 2017-06-24 07:25:32

Thanks bro

By: MX1 at: 2017-07-26 08:08:42

Verry cool. Thanks for the awesome tutorial. Helps me get a jump start on installing the new Cuda tool kit on all my machines. Thanks again awesome!

By: prasad at: 2017-08-04 03:01:17

very good.

By: pk at: 2017-08-16 14:02:55

This is great help! thanks

By: John at: 2017-08-24 08:09:37

Great teaching.

By: dhanyesh at: 2017-09-16 04:22:45

Its very useful and effective. Easy to use it

By: rano at: 2017-09-26 12:19:19

Unable to push. NO enter login credentials prompted after running git push origin master.

fatal: unable to access '': Failed to connect to port 8888: Connection refused

By: bluescreen777 at: 2017-09-26 20:00:04

Thank you for the help!

By: Sravan Chithari at: 2017-09-28 09:51:11

Best article and very helpful :)

By: Mike Paget at: 2017-09-28 10:29:06

Good job! i like it

By: mikesmith123456 at: 2017-10-02 04:37:58

thank you, thank you thank you.

By: Tasos at: 2017-10-18 17:06:42

Dude, you are the only one who managed to put an actual useful guide for first time users. Thanks a lot!

By: Brandon at: 2017-11-10 05:06:19

Perfect tutorial, thank you so much!

By: Freddy Camacho at: 2017-12-20 21:06:11

Hi, Do you have a tutorial on how to install FROM GitHub via terminal? Thank you

By: Ravi yadav at: 2017-12-30 16:03:28

Thanks.....this is a great guide for beginners :)))


By: Darichy at: 2018-01-09 02:46:34

Thats awesome, thanks

By: Ceero at: 2018-02-28 15:52:59

Thanks for this. It was truly helpful

By: Thanku at: 2018-03-07 05:34:15

Thank you so much bro

By: musaah at: 2018-03-18 14:36:19

hello anyone here please i need help

By: Froot at: 2018-03-19 01:07:42

Yes this is ok, Thanks.

By: Zac at: 2018-03-28 00:32:54

Thank you so much. OMFG

By: gaurav agarwal at: 2018-05-01 18:34:07

Reading package lists... Done Building dependency tree Reading state information... Done Package git is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'git' has no installation candidate this is the result what should iI do ?

By: Ludwig at: 2018-05-03 05:28:21

Great guide! Thank you very much!

By: Anon at: 2018-06-05 22:15:09

Very useful, thanks.

By: dnah at: 2018-06-30 01:36:35

thank you a lot

By: Vikram Chaudhary at: 2018-09-13 10:02:20

Thank you the detailed explanation. It really helped.

By: Abhishek Sharma at: 2018-11-24 12:04:52

fatal: remote origin already exists.

this is what i get after 

 git remote add origin


what shoud i do?

By: Abhishek Sharma at: 2018-11-24 12:25:57

error: src refspec master does not match any.

error: failed to push some refs to ''

What is this?

By: Kumar Vivek at: 2018-11-27 04:31:33

Hi I did all the steps but after step 8th "git push origin master" and after adding this command, it is showing 

Below Error


fatal: The current branch master has no upstream branch.

To push the current branch and set the remote as upstream, use

git push --set-upstream origin master

Please help. 

By: eve at: 2018-12-16 06:55:42

Unable to push - I guess its because I have activated the 2 -step security

it ask for username and password. But said it fails: 

remote: Invalid username or password.

fatal: Authentication failed for ''

But it never ask for the second step of the authentification. Any solution?

Best regards, great guide. Thanks!

By: sasnasteve at: 2019-01-01 13:57:27

Excellent, thanks!!

By: sm1km at: 2019-01-10 21:30:51

The git push command doesn't work if you have 2FA enabled. If you have it, you have to disable two-factor authentication or create a Personal Access Token (see

Great guide btw!

By: Karthikeyan at: 2019-03-18 07:13:39

Thanks for your tutorial..Great help for me..

By: ekowahyudisetiawan at: 2019-04-22 04:42:43

thank you, amazing

By: Ethan at: 2019-05-17 15:46:22

Great tutorial, minor typo in 'git add smaple.c'

By: till at: 2019-05-17 16:18:48

Fixed the typo. Thank you for the hint.

By: Mohammad at: 2019-05-28 00:06:10

very nice, worked for me. Thanks.

By: Aravind at: 2019-06-04 20:46:31

very helpful

By: Gautam Helange at: 2019-06-28 16:29:27

Thank you so much. 

By: Moses at: 2019-07-13 14:40:45

Thanks alot, this really helped...

By: Lamu at: 2019-07-22 13:30:16

This has been my first ever successful git commit I've done without a third person..ONLY you and me

By: Raj at: 2019-09-21 04:36:28

Quick and useful intro to using git. Thanks.

By: vijay kumar at: 2019-09-25 14:48:46

you are awesome for explaining step by step for beginners.

By: Shasank at: 2019-11-01 04:37:55

Too good tutorial. Had just to follow steps and then we are done. Thank you very much for this tutorial.

By: dingdong69 at: 2019-12-09 07:51:00

starting with web dev;

thanks 4 d tutorial;

gr8 n very helpful;

By: Jhon Gesell Villanueva Portella at: 2020-02-19 17:41:21

Gracias por compartir la presente entrada, me ha gustado mucho la explicación que han compartido, muy claro todo, saludos desde Lima-Perú.

By: Carmen at: 2020-05-15 19:18:19

This tutorial really help me.. Thank you so much!

By: Ahmadun Nabi at: 2020-06-18 06:50:26

How can I update a file in github? OrA file is already in github, after editing that file how can I push that into github??

By: Socrates at: 2020-07-17 14:46:03

Good job, thanks for your tutorial. Helped me to introduce the procedures in my mind.

By: thomas at: 2020-08-28 15:35:18

Thanks, helps a lot

By: bagusdewantoro at: 2020-09-05 10:01:56

Thanks! great tutorial, very simple. really save my day

By: Kasturi at: 2020-09-27 17:58:40

 Thanks a lottttttttt very much

By: deniz at: 2020-11-08 21:41:47

Your help saved my day:))

By: haicle at: 2021-03-23 23:34:12

Thanks for a short and sweet git tutorial !

By: Tony Nguyen at: 2021-04-28 10:10:54

Year! It worked! Thank you a lot!

By: Tom Dings at: 2021-05-10 02:56:35

Works awesome! Just created this one :

By: Chang Jeon at: 2021-07-06 18:00:00

Very helpful to catch up thanks to your guide. Thank you so much. 

By: amin at: 2021-07-15 15:21:12


By: arslion at: 2021-08-30 23:51:47

github not allowing users to use password anymore. You need to use Personal access tokens for this instead of password.

By: aarvens at: 2021-09-26 05:17:03

Great write-up, thanks! Please update it now that GitHub requires at least personal access tokens to push repos from CLI.

By: Example at: 2023-02-27 13:03:12

Why are you using a probably existing email address of as an example? There are domains like that are exclusivly reserved for examples.