How to Install and Configure Git and Repositories on GitHub on Ubuntu using Command Line


In this post, I am going to demonstrate and guide you through the steps of how to install and configure git and repositories on Ubuntu 17.10 system.

Prerequisites:
  • You need to have a github account. In case you do not have one yet, you may go on the provided link and create your github account. https://github.com/join?source=header
  • You  also need to have Ubuntu installed on your machine.
Instructions:

1. Installing Git
  • To install git on your Ubuntu system, you simply need to go on your terminal and type the following command and hit enter: sudo apt-get install git

2. Configuring GitHub
  • To configure GitHub you need to type the following commands on your terminal and provide with the exact user name and email id which you are using to access your GitHub account:
          git config --global user.name "user_name"

          git config --global user.email "email_id"

3. Create New Repository
  • Go to your GitHub account and create a new repository. Fill in the repository name and add a description which is optional, then click on create repository. You will reach this page as shown below, where the following commands are to be typed on your terminal once you created a directory on your Ubuntu.

4. Creating a Directory on Ubuntu System
  • Once your new repository has been created, you need to create a new directory. Type the following command mkdir and filename in your terminal. In this scenario I am creating a new directory called html. To go to your html directory simply type cd html and hit enter. Right now the directory is empty, so lets continue with the other commands.
5. Creating a README file
  • Now that the directory has been created, it is recommended to create a README file. The README file is generally used to describe what the repository contains or what it is all about. The command to create a README file is: echo "# directory name" >> README.md


6. Initializing Git in the Directory
  • To initialize git type the following command and hit enter: git init
7. Adding the README.md file to Git
  • Simply type git add README.md  and hit enter. This add command adds the file you created to git. 
8. Commit the File
  • Once you added your file, you need to commit the file in order to save the changes in Git. To commit the file simply type this command and hit enter: git commit -m "add a comment here"

9. Linking your GitHub Directory with your Local Directory
  • Here you will need to type the following command and hit enter: git remote add origin URL
10. Push your Changes
  • In order to push your changes you need to type this last command and hit enter: git push -u origin master.
  • You will be prompted to type in your GitHub username and password. Once you do that your changes will be committed in your GitHub directory. You may now refresh your GitHub repository to view the changes.

11. Adding a New File to our Directory
  • Type clear and then ls. We are going to use nano command for creating the new file. Type the following command in your terminal and hit enter: nano sample.txt
  • Once you pressed enter, type in some text then press CTRL+O and hit enter again, this will save your changes and then press CTRL+X to exit. Type ls command to view the file created.
  • Now we have to add the file that we created, type this command and hit enter: git add sample.txt
  • Next,we have to commit this file, type this command and hit enter: git commit -m "type your comments here"
  • Once you committed your file you need to follow the same procedure which we have followed for README file: push -u origin master, then hit enter. Type in your user name and password and hit enter again. You may now refresh the repository on GitHub to view the newly added file.

12. Importing an Existing Project to Ubuntu
  • For this, you will need to save your project on an external drive. Then on your Ubuntu system go to devices and click on USB and select the USB connected on which you saved your project.

  • Go to the files folder on Ubuntu and select the file from the external drive. Transfer the file to your Linux desktop.
  • Go to your terminal and  type: cd Desktop
  • Then type ls command to display the list.
  • Open Firefox browser on your Ubuntu system. Go to your GitHub account and click on the clone or download button.
  • Click on copy link and go back to your terminal.
  • Type the following command and hit enter: git clone paste copied link here for example : git clone https://github.com/Vina07/html.git.
  • Change your current working directory to that of the repository by typing: cd <project folder>
  • Now add any new files to this directory.
  • In order to update the repository with the new files that you have recently added type the following command and hit enter: git add file name or git add -A
  • Type: git status to view whether your files have been queued to be uploaded. They should be labelled in green.
  • Next we need to update, type the following command and hit enter: git push origin

  • In case you want to cancel the command you may press on CTRL+C.
  • In case you want to delete the file simply type this command and hit enter: rm -f file name
  • You may now refresh your GitHub repository to review the changes.

I hope this blog has been helpful to you. Please feel free to leave a comment 😊




Comments

Popular posts from this blog

Linux Shell Scripting

hackers.mu community meetup #1 #2 and #3