Basic Github Usage
Step 1: Create a Local Repository
Create a local directory for your repository:
Navigate into your directory:
Step 3: Connect Your Local Repository to GitHub
Add a remote repository URL to your local repository:
Step 4: Add and Commit Files
Add files to the staging area:
Check the status of your changes:
Commit your changes with a message:
Step 5: Push Changes to GitHub
Check which branch you are on:
Push your changes to GitHub:
Step 6: Pull Latest Changes from GitHub
Pull changes from the remote repository to your local repository:
Password authentication using Token
Option 1: Using a Personal Access Token (PAT)
- Generate a Personal Access Token:
- Go to your GitHub account.
- Navigate to Settings > Developer settings > Personal access tokens.
- Click on “Generate new token”.
- Select the scopes or permissions you’d like to grant this token. For
pushing to a repository, select
repo
. - Generate the token and make sure to copy it; you won’t be able to
see it again once you navigate away from the page.
- Use the PAT instead of your password:
- When prompted for a password in the terminal, enter your personal access token instead of your GitHub password.
Option 2: Using SSH Keys
- Generate SSH Key Pair:
- Open your terminal and run
ssh-keygen -t ed25519 -C "your_email@example.com"
. - Follow the prompts to create your keys, ideally without a passphrase for automation.
- This will create a public and private key pair. The public key ends
in
.pub
and is safe to share.
- Open your terminal and run
- Add your SSH public key to GitHub:
- Navigate to your GitHub account.
- Go to Settings > SSH and GPG keys.
- Click on “New SSH key”, give it a title, and paste your public key.
- Switch your remote URL from HTTPS to SSH:
- Check your current remote URL:
git remote -v
. - Change it to SSH:
git remote set-url origin git@github.com:username/repository.git
.
- Check your current remote URL:
- Push again using SSH:
- Simply run your push command again:
git push origin main
.
- Simply run your push command again: