Installing and Using Git and GitHub on Ubuntu

GitHub is a web-based hosting of the version control system, Git. It allows for teams to easily work on projects, share code, and monitor versions. GitHub has both free and paid services depending on your needs.

This is just a simple tutorial to show you how to install and Use Git and GitHub on Ubuntu.

Notes: Before we get started if you are using GitHub with 2FA, you will need to setup a Personal Assess Token. This can be generated at https://github.com/settings/tokens

Also, if you do not wish to share your email address publicly, you can use your GitHub noreply email address. It will be in the form of [email protected] and can be found at https://github.com/settings/emails

You email address will also need to be verified. Information on this can be found at: https://help.github.com/articles/verifying-your-email-address/

Installing and Using Git and GitHub on Ubuntu

To get started we will need to install Git on Ubuntu. To do this enter the following command into terminal.

sudo apt install git

Once completed, you will now need to set your username and email address. These are your GitHub username and your GitHub noreply email address.

git config --global user.name "username"
git config --global user.email "[email protected]"

Now change to the Home Directory and create your first Git Repository.

cd ~ && git init MyFirstGit

If successful you should see the message: Initialized empty Git repository in /home/owner/MyFirstGit/.git/

Change into the newly created directory

cd MyFirstGit

Create a simple README file and add some text. This can be done with an editor of your choice. A quick sample is shown below.

echo "This is MyFirstGit" > README

Now you can add the file to the index and record changes to the repository

git add README
git commit -m "First commit to GitHub"

Now you need to create a repository on GitHub. This can be done via: https://github.com/new

The repository will need to share the same name as the folder you created earlier, i.e. MyFirstGit. You can leave Initialize this repository with a README unchecked as we have already created this file.

This is a fairly simple procedure but if you get stuck detailed steps can be found here: https://help.github.com/articles/creating-a-new-repository/

Upon creating a new repository you will be given the links to the repository, which should be similar to: https://github.com/username/MyFirstGit.git

We can now add the files to GitHub

git remote add origin https://github.com/username/MyFirstGit.git
git push -u origin master

You will be prompted to enter your username and password (or Personal Access Token if you are using 2FA).

You will now be able to share code and monitor versions the way Linus Torvalds intended.

Change the default editor for Visudo

Visudo is a tool used to safely edit the sudoers file. Visudo locks the sudoers file to ensure multiple users are not trying to edit the file, as well as performing basic sanity checks, and checks for parse errors.

The sudoers file is where you edit the options for sudo. Such as allowing a user to use sudo for all programs – or a handful of programs they require.

To make things easier for people new to Linux, the default editor for Visudo on some Linux distros (i.e. Ubuntu) is Nano. I’ve never really got used Nano. So to make things easier for me I like to swap it back to Vim.

To make changes, we will first have to enter the following command to safely edit the sudoers file.

sudo visudo

This of course will open with nano. Replace the line:

Defaults        editor=/usr/bin/nano

with

Defaults        editor=/usr/bin/vi

and save your file.

Visudo will now open with Vi, the way the greybeards of old intended.

Quit a program on Ubuntu with Alt + Q

It has been just over 3 weeks since I  started using Linux as my daily driver. It hasn’t been an unpleasant experience – although there have been tweaks and fixes along the way.

Instead of bringing over something from Windows that I am so used to having; today’s tweak comes from the Mac – where you can use Command (⌘) + Q to quit a program. This is mush more elegant than Alt + F4 on Windows and Ubuntu.

On my Microsoft 600 Keyboard Alt + Q feels very much like Command (⌘) + Q on the Mac – so I will go with that.

First of all I will remove the old keybinding for Close Window. This can be done by entering the following into a Terminal window.

gsettings set org.gnome.desktop.wm.keybindings close "@as []"

Now I will add the keybinding for Alt + Q. This can be done by entering the following into a Terminal window.

gsettings set org.gnome.desktop.wm.keybindings close "'<Alt>q'"

You can now quit programs on a PC running Ubuntu the way the Apple Corporation running under Steve Jobs intended.

Or close enough to it!

Minimise windows on Ubuntu 18.04 with Super + M

This has turned somewhat into a series of blog posts outlining my transition to Linux as my daily driver. I’m not new to Linux, and have run various variants of Linux on servers (Slackware and Ubuntu mostly). The desktop experience has been a little different as there are certain things I have been so used to on Windows – and I don’t like too much change all at once!

These steps may carry over to other versions of Ubuntu. I will now show you how to Minimise windows on Ubuntu 18.04 with Super + M.

This post will go though changing the ‘minimise all windows’ keyboard shortcut from Control + Super (Windows Key) + D to Super (Windows Key) + M.

Super + M by default on Ubuntu 18.04 opens the Message Tray. The Message Tray can also be opened with Super + V.

First up I will remove the key bindings for ‘toggle message tray’. To do this open Terminal and run the following command:

gsettings set org.gnome.shell.keybindings toggle-message-tray "@as []"

This will  remove the key bindings for both Super + M &  Super + V. We can re-add Super + V so we still have a keyboard shortcut for the message tray with the following command.

gsettings set org.gnome.shell.keybindings toggle-message-tray "['<Super>v']"

Now to add Super + M to minimise windows.

gsettings set org.gnome.desktop.wm.keybindings show-desktop "['<Super>m']"

You can now minimise all open windows the way the 90’s Microsoft Corporation intended.

Fixing the Calculator Key in Ubuntu 18.04

Recently I decided to give Ubuntu 18.04 a go as my daily driver. I have slowly been finding things that do not work as expected, and will blog about them here.

So far I’ve found there was no date in the top bar, my printer doesn’t work, and sudo didn’t curse me if my password was entered incorrectly.

This time my issue is the calculator keyboard shortcut on the Microsoft Wired Keyboard 600, doesn’t open the Calculator. I use this key many times a day, and eventually got sick of searching calc in the Application menu.

I did a bit of Googling and found this post on askubuntu.com, It appears to be a common issue on Ubuntu 18.04 – and fortunately it is a simple fix. Here is a link to the bug report.

The issue looks to be with the gnome-calculator snap package. To fix the issue, first we need to remove gnome-calculator and reinstall it using apt. Type the following commands into a terminal window.

sudo snap remove gnome-calculator

followed by

sudo apt install gnome-calculator

The keyboard shortcut for the fancy abacus will now work as the mighty Sumerian and Egyptian empires intended.