Git Authentication

Fumbani Banda Dec 19, 2022
  1. Create Local Repo From Scratch in Git
  2. Create a Local Repo for an Existing Project
  3. Connect Local Repo to GitHub
Git Authentication

This tutorial demonstrates connecting a local repository to a remote repository on GitHub/Gitlab without getting the authentication failed error message.

Create Local Repo From Scratch in Git

To create a local repository from scratch, follow the following steps.

  • Create a new directory for the project
  • Get inside the new directory
  • Type git init to create a new Git repository.
  • Create files in the new directory
  • While inside the directory, type git add . to add all the files.
  • Type git commit -m "First Commit" to get the changes made to a Git repository.

Create a Local Repo for an Existing Project

To create a local repository for an existing project, follow the following steps.

  1. Get inside the directory of the project
  2. Type git init to initialize the project to a Git repository
  3. Type git add . to add all the files
  4. Type git commit -m "First Commit" to capture the changes made to a Git repository.

Connect Local Repo to GitHub

Once you have a local repository set up, the following instructions provide a guide on connecting to to a remote repository on GitHub.

  • Go to GitHub
  • Log in to your account
  • Create a new repository and copy the URL of the repository.
  • Type the following commands to connect the local git repository to GitHub.
    $ git remote add origin https://github.com/user/repo.git
    

    git remote add origin https://github.com/user/repo.git asks for authentication every time you push. If two-factor authentication is enabled (2FA), you’ll need to use a personl access token (PAT) instead of a password, as shown below. Instead, you can use git remote add origin git@github.com:user/repo.git to avoid authentication for every git action you perform.

    $ git push -u origin master
    

    git username and password

Fumbani Banda avatar Fumbani Banda avatar

Fumbani is a tech enthusiast. He enjoys writing on Linux and Python as well as contributing to open-source projects.

LinkedIn GitHub