Day 10 of my ALX Software Engineering Journey: Source Control (Git and GitHub), Steps to clone a repository.

Day 10 of my ALX Software Engineering Journey: Source Control (Git and GitHub), Steps to clone a repository.

Ever experienced working on a project and all of a sudden your system crashes so you have to start from the beginning or have you ever wished you could return to the previous state of a project you’re working on?

We’ve all been there, but there’s a remedy to this. Today, I’ll be happy to walk you through it.

Source Control

Refers to software that is used to track modifications to your project. Some examples of source control software include git, cvs, and svn.

Git

Is an open-source source control that is widely used to track modifications in projects.

GitHub

Is the cloud service where versions of projects are stored. It’s the web-based version of Git. It permits user interaction with graphics.

Git vs GitHub

Git is a version control that helps you manage your project history.

GitHub is a cloud-based service that helps you manage your Git repository.

Now we’ve been able to differentiate between GitHub and Git, let’s get our hands dirty with how to use version control.

Repository

The first step after creating an account with a source control platform is to create a repository. A repository is a database that stores all these changes and you can create one by following the steps here.

The step below involves creating a repository on GitHub and then cloning the repository to your Git with the aid of an access token.

  1. Create a GitHub account.

  2. Create a repository but without a gitignore and READme file(you would be creating the gitignore and readme file from the git CLI or your terminal).

    note that the gitignore option is set to none

  3. On git CLI, using the command below, clone your repository with your access tokens.

    git clone https://{YOUR_PERSONAL_TOKEN}@github.com/{YOUR_USERNAME}/repository_name.git

(If you don't know what a personal access token is, follow the prompts below, else skip this step).


Personal Access Tokens

There are two types of access tokens: fine grain and classic personal access token. The former is a new feature that enables the feature of limiting the level of access a personal access token gives a user while the latter doesn’t have such feature.

Below are the steps to follow to clone your repository using access tokens

  • Go to developer settings from the settings menu.

  • Head over to the personal access token layer and choose either fine-grained or classic personal access token. I prefer classic personal access token.

  • Generate a new token

  • You can be asked to edit the validity period you would want for the access token. For personal access token, it's best to set it at 'No expiration'

  • You would be tasked to edit what kind of access you would want to give the holder of the personal access token.

  • I like to tick all for my projects and edit the level of access if I’m sharing the personal access token with a third party.

  • Now we’ve got the personal access token it looks like this

  • It’s advised to store the keys in a place you can easily recall them, maybe a notepad or document.

Now let’s clone our repo with the command at number 3.


Done!!!

Now we’ve cloned the GitHub repository let’s navigate to it using the command

cd name_of_repo

The repo has been cloned successfully and you can either decide to add your .gitignore file and README.md file through the terminal or the website.

The .gitignore specifies the files that git shouldn’t track. The README.md file gives a brief description of what your repository is all about.

  • To create a readme.md file you use vi README.md.

  • There are other commands to use but I prefer vi, it's quicker.

  • Switch the mode to insert mode and type.

  • Then exit from the insert mode using esc then type shift + ZZ

Apply the same step to create a .gitignore file.


Git Commands

Most Linux applications have commands, let’s look at some basic git commands that have helped me navigate git:

  1. git init

    this command is used to initialize a git repository in an untracked project.

  2. git commit

    commits are snapshots of the current state of a directory monitored by Git. It stages the changes that have occurred in the state of a file. It can be used with flags to enhance its operation.

  3. git add .

    this command is used to add all changes to files into the staging area. It adds all files that have been modified.

  4. git checkout

    with a branch name, is used to switch between branches.

  5. git merge

    is used to merge changes between branches.

  6. git branch

    when used with a new branch name it creates a new branch.

  7. git status

    is used to determine staged changes and files that are being tracked by Git.

Summary
Source control is a necessary tool for every software engineer to ensure smooth operation. When you think of source control think Git.

Did you find this article valuable?

Support Dillibe by becoming a sponsor. Any amount is appreciated!