Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Comprehensive Git and SSH Guide

This guide covers essential Git commands and SSH setup for version control and remote repository management.

Git Configuration

Setting Up Your Identity

git config --global user.name 'UserName'
git config --global user.email 'temp@gmail.com'

Viewing Your Git Configuration

git config --list

SSH Key Generation and Management

Generate SSH Key

ssh-keygen -t rsa -b 4096 -C "temp@gmail.com"

Start SSH Agent

eval "$(ssh-agent -s)"

Add SSH Key

For Windows:

ssh-add ~/.ssh/id_rsa

For Mac:

ssh-add --apple-use-keychain ~/.ssh/id_rsa

View SSH Public Key

cat ~/.ssh/id_rsa.pub

Remote Repository Management

Connect Local to Remote Repository

git remote add origin git@github.com:UserName/my-notes.git

Check Remote Repository Connection

git remote -v

Update Remote Repository URL

git remote set-url origin git@github.com:UserName/my-notes.git

Basic Git Operations

Check Repository Status

git status

Add Files to Tracking

git add file.js  # Add specific file
git add *.txt    # Add all .txt files
git add .        # Add all files
git add -A       # Add all changes

Rename Files

git mv name.js newName.js

Remove Files from Version Control

git rm --cached my-password.txt  # Remove from Git but keep locally
git reset my-passwords.txt       # Unstage file

Reset to Last Commit

git reset

Commit Changes

git commit -m "add a new task"
git commit --amend -m 'new text'  # Amend last commit

View Commit History

git log
git log -n 2
git log --since=2.weeks
git log --author='UserName'

Stash Management

git stash
git stash save 'my-comment'
git stash list
git stash pop
git stash apply stash@{56f4530}
git stash drop stash@{56d4530}
git stash clear

Pushing Changes

git push
git push -u origin main

Branch Management

Rename Default Branch

git branch -M main

List Branches

git branch -a   # All branches
git branch      # Local branches
git branch -r   # Remote branches

Create and Switch Branches

git switch -c page-header
git switch branch_name

Fetch and Pull Changes

git fetch
git pull origin footer

Merge Branches

git switch main
git pull origin main
git merge page-header
git push origin main

Delete Branches

git branch -d page-header         # Delete merged branch
git branch -D page-header         # Force delete unmerged branch
git push origin --delete footer   # Delete remote branch

Remember to use these commands carefully, especially those that delete or modify branches and commits.

About

Comprehensive Git and SSH Guide

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors