https://github.com/sundanc/git_intro
Introduction to essential and beginner friendly git commands.
https://github.com/sundanc/git_intro
git git-commands git-config github github-actions github-config
Last synced: 4 months ago
JSON representation
Introduction to essential and beginner friendly git commands.
- Host: GitHub
- URL: https://github.com/sundanc/git_intro
- Owner: sundanc
- License: mit
- Created: 2025-02-15T20:21:19.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-02-15T20:21:54.000Z (4 months ago)
- Last Synced: 2025-02-15T21:24:22.720Z (4 months ago)
- Topics: git, git-commands, git-config, github, github-actions, github-config
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Git Commands Reference Guide
## Basic Configuration
```bash
# Configure Git globally
git config --global user.name "Your Username"
git config --global user.email "[email protected]"
git config --global core.editor "code --wait" # Set VS Code as default editor
```## Repository Setup
```bash
# Initialize new repository
mkdir repo-name
cd repo-name
git init# Create initial README
echo "# repo-name" >> README.md
```## Basic Operations
```bash
# Stage changes
git add . # Stage all changes
git add # Stage specific files
git add -p # Stage changes interactively# Commit changes
git commit -m "Commit message"
git commit -am "Commit message" # Stage tracked files and commit# Status and history
git status # Check repository status
git log # View commit history
git log --oneline # Compact history view
git diff # View unstaged changes
git diff --staged # View staged changes
```## Remote Operations
```bash
# GitHub CLI operations
gh auth login # Login to GitHub
gh repo create repo-name --public # Create public repository# Remote repository setup
git remote add origin https://github.com/username/repo-name.git
git remote -v # View remote repositories
git branch -M main # Rename current branch to main
git push -u origin main # Push to remote with upstream tracking# Fetch and pull
git fetch origin # Download objects and refs
git pull origin main # Fetch and merge changes
git clone # Clone existing repository
```## Branch Management
```bash
# View branches
git branch # List local branches
git branch -a # List all branches including remote
git branch --show-current # Show current branch name# Branch operations
git checkout # Switch branches
git checkout -b # Create and switch to new branch
git branch -d # Delete local branch
git push origin --delete # Delete remote branch
git merge # Merge branch into current
git merge --abort # Abort merge in case of conflicts
```## Undo Operations
```bash
# Undo changes
git reset --soft HEAD~1 # Undo last commit, keep changes staged
git reset --mixed HEAD~1 # Undo last commit, keep changes unstaged
git reset --hard HEAD~1 # Undo last commit, discard changes
git revert # Create new commit that undoes changes
git checkout -- # Discard changes in working directory
git clean -fd # Remove untracked files and directories
```## Stashing
```bash
# Stash operations
git stash # Quick stash
git stash save "message" # Stash with message
git stash list # List all stashes
git stash show # Show stash contents
git stash apply # Apply most recent stash
git stash apply stash@{n} # Apply specific stash
git stash drop # Remove most recent stash
git stash clear # Remove all stashes
```## Advanced Inspection
```bash
# Detailed inspection
git show # Show commit details
git blame # Show who changed what
git reflog # View reference logs
git log --graph --oneline # Show branch graph
git bisect start # Binary search for bugs
```## Submodules
```bash
# Submodule operations
git submodule add # Add submodule
git submodule init # Initialize submodules
git submodule update # Update submodules
git submodule update --init --recursive # Initialize and update recursively
```## Aliases
```bash
# Create aliases
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
```## Best Practices
- Write clear, concise commit messages
- Commit frequently, push regularly
- Use meaningful branch names
- Pull before pushing to avoid conflicts
- Keep main/master branch stable
- Use `.gitignore` for project-specific exclusions
- Review changes before committing
- Create feature branches for new work
- Delete merged branches to keep repository clean