Git Authentication
- Create Local Repo From Scratch in Git
- Create a Local Repo for an Existing Project
- Connect Local Repo to GitHub
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.
- Get inside the directory of the project
- Type
git init
to initialize the project to a Git repository - Type
git add .
to add all the files - 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. Iftwo-factor authentication
is enabled (2FA), you’ll need to use apersonl access token
(PAT) instead of a password, as shown below. Instead, you can usegit remote add origin git@github.com:user/repo.git
to avoid authentication for every git action you perform.$ git push -u origin master