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.