Skip to main content

Git and GitHub

Updated 3 min readMarkdown

GitHub is a web-based hosting service for version control using Git.
It is a central repository. It provides access control and several collaboration features such as bug tracking, feature requests, and task management.
Public repository is free but maintaining a private repository is a paid service.
Open-source developers created GitLab to make everything free. Bitbucket is also an alternative to GitHub.

Connect to Central Repo (GitHub):-

First, you need to create your GitHub account and a repository in your account.

  1. Go to the GitHub site [https://github.com] and create an account

  2. Create a "New Repository"

  3. Login to your EC2 Instance and create your working directory
    mkdir new-git ; cd new-git ; git status ;

  4. Clone the Repository
    git clone https://github.com/<Name>/firstrepo-public;
    cd firstrepo-public

  5. Create a new file, add it to staging, and do the commit
    echo "New File..." > firstrepo.txt
    git add firstrepo.txt
    git commit -m "First Commit"

  6. Check which remote repository is connected:
    git remote -v

  7. Generate a token to give permissions for the remote user for the GitHub Repo.
    Else, you will be prompted for a username and password, will the pull and push requests.

Login to your Github > Settings > Developer Settings > Personal access tokens > Tokens(classic) > Generate new token > Generate new token(classic) > Assign a

Token Note - choose the Expiration period and select what permissions you want to give to this particular token. -> Generate Token -> Copy the token

  1. Use, the token and the Repo URL, that we created earlier

    git remote set-url origin https://ghp=L0i4HLonwhnKash2KzcnXGb2K3We1qy@github.com/kcG/firstrepo-public

    i.e
    https://<Personal-access-tokens-Key>@github.com/<Git-Username>/<Repo-URL>

    https://ghp_49pQuYE7-PerSonap-Tokken-Key@github.com/ketangharateG/react_django_demo_app

  2. Verify the origin will get changed
    git remote -v

  3. Now, push your local repo to the central repo.
    [Your local repo data will be copied to the central repo]

    git push origin master

  4. Now, To pull from the remote repo.
    [Download from central repo to your local repo]

    git pull origin master

    If pulling branches other than master, change the branch name.
    Create a new file on the Central repo and try to pull them.

  • Collaborate between Local and Remote Repository using
    git pull and git push

Pull the commits from the Remote Repository
git pull origin master
git push origin master

ORIGIN: Git indicates that a remote repository can be added and identified with a keyword known as origin.

  • Git enables moving files from the Local Repository to the Remote Repository using
    HTTPS
    OR
    SSH

  • Create a Repository in GitHub using SSH

  1. Ensure the local Repois ready

  2. Create SSH Key using (ssh-keygen)

  3. Configure GitHub with SSH Public Key

  4. Create a Github Repo

  5. Push from Local Repo to GitHub

  • Create a Repository in GitHub using HTTPS

    • Go to GitHub and login

    • Create a New Repository

    • Follow GitHub Instructions
      git remote -v
      git remote add origin https://github.com/<Repo-Name>
      - When you will create Repo you will be shown the cmd line instructions.
      - You can also copy the URL from GitHub > Repo > Code <>section
      git remote -v
      git push origin master

30 views

No comments yet. Be the first to comment.

More from this blog