Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Using SSH keys to interact with GitHub is more secure and avoids typing your username/password or token repeatedly.
- Step-by-step guide to upload all your files to a GitHub repo using SSH.
- ##################################################################
- Join our telegram channel for more : https://t.me/LinuxClassesEFXTv
- ##################################################################
- ๐งฐ Prerequisites
- - Git installed (git --version)
- - GitHub account
- - SSH key configured (we'll cover that below)
- โ Step 1: Create an SSH Key (if you don't already have one)
- Check if you already have a key:
- ls ~/.ssh/id_rsa.pub
- If it exists, you can skip to Step 2.
- Otherwise, generate one:
- ssh-keygen -t ed25519 -C "[email protected]"
- Press Enter to accept the default file location.
- Set a passphrase (optional but recommended).
- ๐ Step 2: Add Your SSH Key to GitHub (Copy the entire output)
- cat ~/.ssh/id_ed25519.pub
- Add it to GitHub:
- - Go to https://github.com/settings/keys
- - Click "New SSH key"
- - Paste the key, give it a name, and save
- Step 3: Configure SSH for GitHub (optional but helpful)
- nano ~/.ssh/config
- Add this:
- Host github.com
- HostName github.com
- User git
- IdentityFile ~/.ssh/id_ed25519
- ๐ Step 4: Test the SSH Connection
- ssh -T [email protected]
- You should see:
- Hi yourusername! You've successfully authenticated, but GitHub does not provide shell access.
- Step 5: Create a GitHub Repo (via website)
- Go to https://github.com/new, create an empty repository without initializing with README.
- ๐ Step 6: Upload Your Files to GitHub (via SSH)
- - Navigate to your project folder: (Copy new files if you want to copy)
- cd /path/to/your/project
- Initialize git:
- git init
- Add all files:
- git add .
- Step 7: Set Your Git Identity
- git config --global user.name "Your Name"
- git config --global user.email "[email protected]"
- Commit:
- git commit -m "Initial commit"
- ๐ Step 7:Add your GitHub repo via SSH:
- git remote add origin [email protected]:username/repo.git
- ๐ Step 8: Push
- git push -u origin main
- ๐ EXTRAS: Delete files and add new files:
- ๐งน 1. Delete the File Locally
- rm path/to/file.ext
- ๐งน 2. Tell Git About the Deletion:
- rm path/to/file.ext
- ๐ adds changes to tracked files only:
- - Stages deleted files
- - Stages modified files
- - Does not stage new (untracked) files
- git add -u
- ๐ To Add New Files
- 1. Copy or create the new files in your repo folder (locally)
- cp path/to/nefile.ext .
- 2. Add the new files to Git:
- git add path/to/newfile.ext
- Or to add everything new:
- git add .
- ๐ Commit the Changes
- git commit -m "Remove unused files and add new ones"
- ๐ Push to GitHub
- git push
- ๐งฝ Optional: Delete a Remote File Without Deleting It Locally
- git rm --cached path/to/file.ext
- ๐ How to rename a file/folder in Git (do not use .ext for folders):
- 1. Use git mv to rename:
- git mv old_filename.ext new_filename.ext
- 2. Commit the rename:
- git commit -m "Rename old_filename.ext to new_filename.ext"
- 3. Push the changes (if you use remote repo):
- git push
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement