Create, Push, Pull Repo in GitHub

Create, Push, Pull Repo in GitHub

Hi, in today's blog, I will share with you how to

  • Create a Repository on GitHub

  • Pull the Repository from GitHub to the local machine

  • Push changes in the Repository on GitHub

Prerequisite

First, you need to have installed Git in your local system.

Secondly, an account on GitHub.

If you do not have any of these, don't worry. Just follow the steps.

Install Git

  1. Open your Linux terminal.

  2. Update the packages:

     sudo apt-get update
    
  3. Install the Git

     sudo apt-get install git -y
    

And you are done with installing Git in your system.

Verify Git

Let's verify whether Git is installed or not by checking the version of Git:

git --version

Now you have Git installed. Let's go the GitHub and create an account.

Create GitHub Account

To create an account on GitHub visit: https://github.com/ This is GitHub's official website.

Here, Click on sign up and enter:

  • Email

  • Password

  • Name

    etc.

After that, it may ask you to verify your email.

That's it. Your account is ready.

Create a Repository on GitHub

To create a repository, go to https://github.com/new

You will see a form like the above image. Fill up the form.

  1. Enter the repository name, I have chosen Devops-Day08-Challenge as my new repository name.

  2. You can describe the repository in the Description. I have written: This is my Day 8 challenge of #90DaysOfDevops

  3. Click on Create repository button.

Your repository has been made and is ready to use.

Setup Git

Now, let's go to our machine and create a version control and add with remote one.

Username and Email

To use git you have to give your email and username to git for tracking records.

  1. Open the command line.

  2. Set your username:

     git config --global user.name "FIRST_NAME LAST_NAME"
    
  3. Set your email address:

     git config --global user.email "MY_NAME@example.com"
    

Git init, add, commit.

  1. Open terminal.

  2. Create a folder name Devops-Day08-Challenge (similar to the repo)

  3. Make this folder a version control with git.

    1.   git init
      

  4. Add some files to the folder.

    1. I will add a readme file.

       vim README.md
      
    2. Write some description in this file:

  5. Stage this file to Git version control:

     git add README.md
    
  6. Commit this change to git with a message.

     git commit -m "initial commit"
    

Add Repository in Git

  1. Use the git remote add command to add the repo to git.

     git remote add origin https://github.com/neelsoni26/Devops-Day08-Challenge.git
    
  2. Verify with -v :

     git remote -v
    

Personal Access token

To push and pull the repository you need to have Personal access token for the password.

To create your Personal access token:

  1. Go to GitHub Settings > Developer settings> Personal access tokens >tokens (classic)

    1. Or simply visit: https://github.com/settings/tokens
  2. Click on Generate New Tocken

    1. Generate new token (classic)

  1. Give a name

  2. Set Expire

  3. Select scopes (Permission of)

  4. Click Generate token.

  5. Copy the token and save it in a safe place.

Push the Change

To push the changes from local Git to GitHub git push command is used.

git push origin master

Enter username and Personal access token.

Done! Your changes are now on GitHub.

Pull the Change

Now let's say you have made some changes on the GitHub website in the repository, How you will get that in your local repository?

Simple, Using git pull command.

Suppose, I update the README.md file from the website.

I have updated it to give a link in the text.

And commit to the change.

To get this change in my local I will run the command:

git fetch -all
git pull origin master

Now let's check the change.

Done. You have Created, Pushed and Pulled the repository from GitHub.

If you like the post do like, have any queries? do comment and share the blog ๐Ÿ˜Š

ย