How to configure a Git repository using Linux CLI?
Overview
This tutorial provides a general overview of how to set up a Git repository using the Linux command line. It introduces the essential Git operations and guides you through the process of creating a new or ongoing Git repository. This tutorial assumes that you have some familiarity with the command line
Prerequisites
Already created GitHub account.
Ubuntu 20.04
SSH connected text editor
Internet connection
Get Started
Step 1: Git Installation
Git requires several dependencies to build on Linux, which can be fulfilled via apt, so we’ll use the same to install the latest version of git.
Enter into root user.
Update your system with the following command:
Download and install git, using the following command:
Verify the installation by running the following command:
Step 2: Git Proxy Configuration
Use the following commands to set up your Git login and email. Be sure to use your own name in place of DEMO. These credentials will be connected to any commits you make.
Step 3: Creating a new Repo
Login to the official GitHub page and make a new repository.
Step 4: Basic Git Workflow
Note: Kindly insert your own values in between <>, wherever given.
Make a folder / directory on the command line of your Linux machine, using the following command:
Create a file in the recently made folder:
Initialize the git repository, by using the following command:
Let’s see the current position of our working directory and staging area. It will show the files and folders, ready to be added:
Use the add command to add the files to the staging area. It also prepares the staged items to be committed next.
Note: The above command will add all the files and folders of that particular folder to the staging area. If you want any particular file to be staged, use the following command instead:
You may check again the status of your files, by using git status
command. Save all the changes made to the working directory by using the following command takes everything in the staging area and makes a permanent snapshot of your repo’s current state.
In the directory, where your repo is stored, add a new remote using the following command on the terminal:
Two arguments are required for the git remote add
command:
A remote name, for instance, origin.
A remote URL address, like https://github.com/user/repo.git
To push the latest changes to the central working directory, the following command is used:
To clone or copy an existing repo in your new directory, the following command is used:
Last updated