test
This commit is contained in:
commit
9212996247
6 changed files with 370 additions and 0 deletions
0
.test
Normal file
0
.test
Normal file
55
github/1_prerequisites_github_ubuntu.md
Normal file
55
github/1_prerequisites_github_ubuntu.md
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
## 📘 `1_prerequisites_github_ubuntu.md`
|
||||||
|
|
||||||
|
### 📌 Purpose
|
||||||
|
|
||||||
|
Prepare your Ubuntu system to create and work with remote GitHub repositories using SSH.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### ✅ System Requirements
|
||||||
|
|
||||||
|
* **Install Git**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install git -y
|
||||||
|
```
|
||||||
|
|
||||||
|
* **Create a GitHub account**
|
||||||
|
👉 [https://github.com/join](https://github.com/join)
|
||||||
|
|
||||||
|
* **Set your Git identity**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git config --global user.name "Your Name"
|
||||||
|
git config --global user.email "your_email@example.com"
|
||||||
|
```
|
||||||
|
|
||||||
|
* **Generate an SSH key (if not already present)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
|
||||||
|
eval "$(ssh-agent -s)"
|
||||||
|
ssh-add ~/.ssh/id_rsa
|
||||||
|
```
|
||||||
|
|
||||||
|
* **Add your SSH public key to GitHub**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cat ~/.ssh/id_rsa.pub
|
||||||
|
```
|
||||||
|
|
||||||
|
🔗 Copy the output and paste it at:
|
||||||
|
GitHub → Settings → SSH and GPG keys → *New SSH key*
|
||||||
|
|
||||||
|
* **Test the connection**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh -T git@github.com
|
||||||
|
```
|
||||||
|
|
||||||
|
You should see:
|
||||||
|
|
||||||
|
> "Hi `your-username`! You've successfully authenticated..."
|
||||||
|
|
||||||
|
---
|
73
github/2_create_remote_repo_github_ubuntu.md
Normal file
73
github/2_create_remote_repo_github_ubuntu.md
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
## 📘 `2_create_remote_repo_github_ubuntu.md`
|
||||||
|
|
||||||
|
### 📌 Purpose
|
||||||
|
|
||||||
|
Create a new remote repository on GitHub and push your local Ubuntu-based Git project to it.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🪐 Step-by-Step
|
||||||
|
|
||||||
|
#### Step 1: Create the remote repository
|
||||||
|
|
||||||
|
1. Go to [https://github.com/new](https://github.com/new)
|
||||||
|
2. Set:
|
||||||
|
|
||||||
|
* Repository Name
|
||||||
|
* Visibility (Public or Private)
|
||||||
|
* ✅ Leave **"Initialize with README"** unchecked
|
||||||
|
3. Click **Create repository**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### Step 2: Prepare your local repository
|
||||||
|
|
||||||
|
If starting fresh:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir myproject
|
||||||
|
cd myproject
|
||||||
|
git init
|
||||||
|
```
|
||||||
|
|
||||||
|
If converting an existing project:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd myproject
|
||||||
|
git init
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### Step 3: Add files and commit
|
||||||
|
|
||||||
|
```bash
|
||||||
|
touch README.md # or edit existing files
|
||||||
|
git add .
|
||||||
|
git commit -m "Initial commit"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### Step 4: Link to GitHub remote
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git remote add origin git@github.com:your-username/your-repo-name.git
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### Step 5: Push to GitHub
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git push -u origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
> If you get an error about `main` not existing:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git branch -M main
|
||||||
|
git push -u origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
51
github/3_commit_existing_repo_github_ubuntu.md
Normal file
51
github/3_commit_existing_repo_github_ubuntu.md
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
## 📘 `3_commit_existing_repo_github_ubuntu.md`
|
||||||
|
|
||||||
|
### 📌 Purpose
|
||||||
|
|
||||||
|
Work with an existing remote GitHub repository on Ubuntu. This includes cloning, committing changes, and pushing updates.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🛠️ Step-by-Step
|
||||||
|
|
||||||
|
#### Step 1: Clone the repository
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone git@github.com:your-username/your-repo-name.git
|
||||||
|
cd your-repo-name
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### Step 2: Make your changes
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nano example.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
Or update files as needed.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### Step 3: Stage and commit your changes
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add .
|
||||||
|
git commit -m "Describe your update"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### Step 4: Push to GitHub
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
> Use the correct branch name if not `main`. Confirm with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git branch
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
97
github/CLI-ONLY_workflow_github_ubuntu.md
Normal file
97
github/CLI-ONLY_workflow_github_ubuntu.md
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧭 FULL CLI-ONLY WORKFLOW (Ubuntu + GitHub)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🔹 Step 1 — Install prerequisites
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install Git
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install git -y
|
||||||
|
|
||||||
|
# Install GitHub CLI
|
||||||
|
type -p curl >/dev/null || sudo apt install curl -y
|
||||||
|
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | \
|
||||||
|
sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
|
||||||
|
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
|
||||||
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] \
|
||||||
|
https://cli.github.com/packages stable main" | \
|
||||||
|
sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install gh -y
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🔹 Step 2 — Authenticate with GitHub
|
||||||
|
|
||||||
|
```bash
|
||||||
|
gh auth login
|
||||||
|
```
|
||||||
|
|
||||||
|
* Choose: `GitHub.com`
|
||||||
|
* Protocol: `SSH`
|
||||||
|
* Authenticate via browser (first time only—after that you're CLI-auth’d)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🔹 Step 3 — Set global Git identity
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git config --global user.name "Your Name"
|
||||||
|
git config --global user.email "your_email@example.com"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🔹 Step 4 — Create and link a new GitHub repo (CLI-only)
|
||||||
|
|
||||||
|
From inside your project directory:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir myproject
|
||||||
|
cd myproject
|
||||||
|
git init
|
||||||
|
echo "# My Project" > README.md
|
||||||
|
git add .
|
||||||
|
git commit -m "Initial commit"
|
||||||
|
```
|
||||||
|
|
||||||
|
Now create a GitHub repo **from the CLI**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
gh repo create myproject --public --source=. --remote=origin --push
|
||||||
|
```
|
||||||
|
|
||||||
|
✅ This:
|
||||||
|
|
||||||
|
* Creates the remote GitHub repo
|
||||||
|
* Links it to your local repo
|
||||||
|
* Pushes your first commit to GitHub
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🔹 Step 5 — Make further commits
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Edit files as needed
|
||||||
|
nano something.txt
|
||||||
|
|
||||||
|
# Stage + commit + push
|
||||||
|
git add .
|
||||||
|
git commit -m "Updated something"
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🔹 Bonus — Clone a GitHub repo entirely from CLI
|
||||||
|
|
||||||
|
```bash
|
||||||
|
gh repo clone your-username/your-repo
|
||||||
|
cd your-repo
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
94
github/gitlink-github.sh
Executable file
94
github/gitlink-github.sh
Executable file
|
@ -0,0 +1,94 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
GIT_REMOTE_NAME="github"
|
||||||
|
REPO_NAME=$(basename "$(pwd)")
|
||||||
|
|
||||||
|
# ────────────────
|
||||||
|
# Logging Helpers
|
||||||
|
# ────────────────
|
||||||
|
info() { echo -e "\e[1;34m[INFO]\e[0m $*"; }
|
||||||
|
warn() { echo -e "\e[1;33m[WARN]\e[0m $*"; }
|
||||||
|
error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; }
|
||||||
|
|
||||||
|
# ────────────────
|
||||||
|
# Check/install git
|
||||||
|
# ────────────────
|
||||||
|
if ! command -v git &>/dev/null; then
|
||||||
|
info "Installing git..."
|
||||||
|
sudo apt update && sudo apt install git -y || error "Failed to install git"
|
||||||
|
else
|
||||||
|
info "Git already installed: $(git --version)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ────────────────
|
||||||
|
# Check/install GitHub CLI
|
||||||
|
# ────────────────
|
||||||
|
if ! command -v gh &>/dev/null; then
|
||||||
|
info "Installing GitHub CLI..."
|
||||||
|
type -p curl >/dev/null || sudo apt install curl -y
|
||||||
|
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | \
|
||||||
|
sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
|
||||||
|
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
|
||||||
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] \
|
||||||
|
https://cli.github.com/packages stable main" | \
|
||||||
|
sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
|
||||||
|
sudo apt update && sudo apt install gh -y || error "Failed to install GitHub CLI"
|
||||||
|
else
|
||||||
|
info "GitHub CLI already installed: $(gh --version | head -n 1)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ────────────────
|
||||||
|
# Authenticate GitHub CLI
|
||||||
|
# ────────────────
|
||||||
|
if ! gh auth status &>/dev/null; then
|
||||||
|
info "Authenticating GitHub CLI..."
|
||||||
|
gh auth login || error "GitHub authentication failed"
|
||||||
|
else
|
||||||
|
info "GitHub CLI authenticated as: $(gh auth status | grep 'Logged in as' | cut -d ':' -f2 | xargs)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ────────────────
|
||||||
|
# Initialize Git Repo
|
||||||
|
# ────────────────
|
||||||
|
if [ ! -d ".git" ]; then
|
||||||
|
info "Initializing local Git repo..."
|
||||||
|
git init || error "Git init failed"
|
||||||
|
git add . || warn "No files to add"
|
||||||
|
git commit -m "Initial commit" || warn "Nothing to commit"
|
||||||
|
else
|
||||||
|
info "Git repo already initialized."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ────────────────
|
||||||
|
# Create GitHub remote if missing
|
||||||
|
# ────────────────
|
||||||
|
if ! git remote get-url "$GIT_REMOTE_NAME" &>/dev/null; then
|
||||||
|
info "Creating GitHub repo '$REPO_NAME' via CLI..."
|
||||||
|
gh repo create "$REPO_NAME" --public --source=. --remote="$GIT_REMOTE_NAME" --push || error "GitHub repo creation failed"
|
||||||
|
else
|
||||||
|
info "Remote '$GIT_REMOTE_NAME' already set to: $(git remote get-url $GIT_REMOTE_NAME)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ────────────────
|
||||||
|
# Commit changes if needed
|
||||||
|
# ────────────────
|
||||||
|
if ! git diff --quiet || ! git diff --cached --quiet; then
|
||||||
|
info "Changes detected — committing..."
|
||||||
|
git add . || warn "Nothing staged"
|
||||||
|
git commit -m "Update: $(date '+%Y-%m-%d %H:%M:%S')" || warn "Nothing to commit"
|
||||||
|
else
|
||||||
|
info "No uncommitted changes."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ────────────────
|
||||||
|
# Push if branch is ahead
|
||||||
|
# ────────────────
|
||||||
|
if git status | grep -q "Your branch is ahead"; then
|
||||||
|
info "Pushing changes to GitHub..."
|
||||||
|
git push "$GIT_REMOTE_NAME" "$(git rev-parse --abbrev-ref HEAD)" || error "Push failed"
|
||||||
|
else
|
||||||
|
info "No push needed. Local and remote are synced."
|
||||||
|
fi
|
Loading…
Add table
Add a link
Reference in a new issue