Installing Git
Guide to installing Git, performing the initial setup, and connecting your environment with GitHub.
Requirements
Operating System | Version |
---|---|
Debian | 10 |
Installation
Refresh the package index.
sudo apt-get update
Remove any previous installation.
sudo apt-get remove git
Install Git from the official repositories.
sudo apt-get install git
Verification
Check the installed version.
git --version
git version 2.17.1
Initial Configuration
View the current configuration.
git config --list
Set your global identity.
git config --global user.name "John Smith"
git config --global user.email "john.smith@example.com"
Working Locally Without a Remote
You can initialize a local repository in any folder with git init
.
cd app
git init
git status
Cloning Repositories from GitHub
GitHub hosts public and private repositories. Clone them over HTTPS or SSH.
Clone via HTTPS.
git clone https://github.com/username/project.git
Clone via SSH.
git clone git@github.com:username/project.git
Note: Using SSH requires registering your public key with GitHub.
Change the Project's Remote URL
Link your local repository to a remote destination.
git remote add origin git@github.com:username/project.git
Switch the remote URL to HTTPS.
git remote set-url origin https://github.com/username/project.git
Switch the remote URL to SSH.
git remote set-url origin git@github.com:username/project.git
Inspect the configured remotes.
git remote -v
origin https://github.com/username/project.git (fetch)
origin https://github.com/username/project.git (push)
Configure SSH Keys for GitHub
Check for existing SSH keys.
ls -l ~/.ssh
If none are present, generate one following Creación de llaves SSH.
Copy the public key
id_rsa.pub
.cat ~/.ssh/id_rsa.pub
Paste it under Settings > SSH and GPG keys in your GitHub account.
Verify the connection with:
ssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
GitHub Personal Access Tokens
Personal access tokens let you authenticate over HTTPS when working with private repositories.
Go to Settings > Developer settings > Personal access tokens and create a token with the scopes you need (for example, repo).
Use the token instead of your password whenever Git requests HTTPS credentials.
Example: Cloning a private repository with a token.
git clone https://github.com/username/my-private-project.git
Clonando en 'my-private-project'...
Username: git
Password: your_token
References
Published: May 24, 2020