0% found this document useful (0 votes)
11 views21 pages

Claude Tutorial

This document is a comprehensive guide to GitHub commands, covering everything from setup and configuration to advanced operations like rebasing and cherry-picking. It includes sections on basic repository operations, working with files, branching, merging, remote repository operations, and GitHub-specific commands. The guide is structured to assist beginners and advanced users alike in effectively using Git and GitHub for version control and collaboration.

Uploaded by

codexz786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
11 views21 pages

Claude Tutorial

This document is a comprehensive guide to GitHub commands, covering everything from setup and configuration to advanced operations like rebasing and cherry-picking. It includes sections on basic repository operations, working with files, branching, merging, remote repository operations, and GitHub-specific commands. The guide is structured to assist beginners and advanced users alike in effectively using Git and GitHub for version control and collaboration.

Uploaded by

codexz786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 21
Complete GitHub Commands Guide - Beginner to Advanced Table of Contents 1, Setup & Configuration 2. Basic Repository Operations 3. Working with Files 4, Branching & Merging 5, Remote Repository Operations 6. Viewing History & Information 7. Undoing Changes 8. Stashing 9. Tagging rations 10. Advanced Oy specific Commands Setup & Configuration Initial Setup (One-time only) bash # Set your name and enail globally git config --global user.nane "Your Name" git config --global user.enail "your.enailgexample,con" # Set default branch name to 'main' git config --global init.defaultBranch main # Set default editor (optional) git config --global core.editor "code --wait" # For VS Code git config --global core.editor "nano" # For nano # View all configurations git config --list # View specific configuration git config user.name git config user.email Basic Repository Operations Creating & Initializing Repositories bash # Initialize a new Git repository in current directory git init # Initialize with specific branch name git init --i branch=nain # Clone an existing repository git clone https: //github, con/username/repository-name, git # Clone to a specific directory git clone https: //github.com/username/repository-nane.git my-project # Clone only the Latest conmit (shallow clone) git clone --depth 1 https: //github.con/username/repository-nane. git Basic Status & Information bash # Check repository status git status # Short status format git status -s # Check which files are tracked/untracked git 1 Working with Files Adding Files to Staging Area bash # Add a specific file git add filename.tx # Add multiple specific files git add file1. tf # Add all files in current directory git add . # Add all files in repository git add -A # Add all modified files (not new files) git add -v # Add files interactively git add -i # Add specific parts of a file git add -p filename bash # Commit with message git commit -m "Your commit message here" # Commit with detailed message git commit -m "Short description" -m "Longer description with more details’ # Add and conmit in one command git commit -am "Add and commit message" # Commit with editor for Long message git commit # Amend the Last conmit (change message or add files) git commit --amend -m "New commit message” # Commit without hooks git commit --no-verify -m "Commit message" Removing Files bash # Remove file from working directory and staging area git rm filename, txt # Remove file only from staging area (keep in working directory) git rm --cached filename. txt # Remove directory git rm =r directory-name/ # Force remove (if file has changes) git rm -f filename.txt Branching & Merging Branch Operations bash # List all local branches git branch # List all branches (Local and remote) git branch -a # List remote branches only git branch =r # Create a new branch git branch new-branch-name # Create and switch to new branch git checkout -b new-branch-name # Modern way to create and switch git switch -c new-branch-nane # Switch to existing branch git checkout branch-nane git switch branch-name # Switch to previous branch git checkout - git switch - # Rename current branch git branch -m new-branch-name # Rename any branch git branch -m old-name new-nane # Delete a branch (safe - prevents deletion if unmerged) git branch -d branch-name # Force delete a branch git branch = branch-nane # Delete remote branch git push origin --delete branch-nane Merging bash # Merge a branch into current branch git merge branch-name # Merge with no fast-forward (creates merge conmit) git merge --no-f¥ branch-name # Merge with custom commit message git merge branch-name -m "Merge message" # Abort a merge in progress git merge --abort # Continue merge after resolving conflicts git merge --continue Remote Repository Operations Working with Remotes bash # Add @ remote repository git remote add origin https: //github. com/usi rname/repository-name, git # List all remotes git remote -v # Show detailed info about a renote git remote show origin # Rename a remote git remote rename origin upstream # Remove a remote git remote remove origin # Change remote URL git remote set-url origin https://github. com/username/new-repository.git Fetching & Pulling bash # Fetch changes from remote (doesn't merge) git fetch # Fetch from specific renote git fetch origin # Fetch specific branch git fetch origin branch-nane # PuLl changes (fetch + merge) git pull i# Pull from specific remote and branch git pull origin main # Pull with rebase instead of merge git pull --rebase # Pull and automatically stash/unstash Local changes git pull --autostash Pushing bash # Push to remote repository git # Push to specific remote and branch git # Push and set upstream branch git # Push all. branches git # Push tags git # Force push (dangerous - use carefully) git # Safer force push git # Push specific tag git Viewing History & Informat Commit History bash it View commit history git log # Compact one-Line format git log --oneline # Show Last n conmits git log -n 5 # Show commits with file changes Bit log --stat # Show commits with actual changes git log -p # Show conmits in graph format git log --graph --oneline --al1 # Show commits by author git log --author="author Name" # Show conmits since specific date git log --since="2024-@1-01" # Show conmits for specific file git log filename. txt # Show conmits with specific message Bit log --grep="bug fix" Viewing Changes bash # See unstaged changes git diff # See staged changes git diff --staged git diff --cached # Compare two branches git diff branch1. .branch2 # Compare specific conmits git diff commiti conmit2 # See changes in specific file git diff filename.txt # Show changes with word-Level highlighting git diff --nord-diff Blame & Show bash # See who changed each Line in a file git blame filename.txt ‘# Show details of specific commit git show comnit-hash # Show files changed in conmit git show --name-only connit-hash # Show specific file at specific commit Bit show connit-hash: filename, txt Undoing Changes Unstaging Changes bash # Unstage a file git reset filename. txt # Unstage all files git reset # Reset to specific commit (keep changes in working directory) git reset commit-hash # Reset and discard all changes (dangerous) git reset --hard commit-hash Reverting Changes bash # Revert unstaged changes in file git checkout -- filename.txt # Revert all unstaged changes git checkout ==. # Modern way to restore file git restore filename.txt # Restore all files git restore . # Restore staged file to unstaged git restore --staged filename. txt # Create new commit that undoes a previous commit git revert commit-hash # Revert without creating conmit git revert --no-commit conmit-hash Stashing Basic Stashing bash # Stash current changes git stash # Stash with message git stash push -m "Work in progress on feature X" # List all stashes git stash list # Apply most recent stash git stash apply # Apply specific stash git stash apply stash@{2} # Apply stash and remove from stash List git stash pop # Drop specific stash git stash drop stash@(2} # Clear all stashes git stash clear # Show stash contents git stash show -p stash@{e} Advanced Stashing bash # Stash only staged changes git stash push --staged # Stash including untracked files git stash push -v # Stash everything including ignored files git stash push -a # Stash specific files git stash push -m "message" -- filename. txt # Create branch from stash git stash branch new-branch-name stash@{@} Tagging Creating Tags bash # Create Lightweight tag git tag v1.0.0 # Create annotated tag with message git tag -a v1.0.0 -m "Version 1.2.8 release" # Tag specific conmit git tag -a v1.0.0 commit-hash -m "Version 1.8.0’ # List all tags git tag # List tags matching pattern git tag -1 "vi." # Show tag information git show v1.0.0 Managing Tags bash # Delete local tag git tag -d v1.0.0 # Delete remote tag git push origin --delete tag v1.2.8 # Push specific tag git push origin v1.0.0 # Push all tags git push --tags Advanced Operations Rebasing bash # Rebase current branch onto another branch git rebase main # Interactive rebase (Last 3 commits) git rebase -i HEAD~3 # Interactive rebase from specific commit git rebase -i conmit-hash # Continue rebase after resolving conflicts git rebase --continue # Skip current commit during rebase git rebase --skip # Abort rebase git rebase --abort # Rebase and automatically resolve conflicts using theirs/ours git rebase -x theirs branch-name git rebase -X ours branch-name Cherry-picking bash # Apply specific commit to current branch git cherry-pick conmit-hash # Cherry-pick multiple commits git cherry-pick commit connit2 conmit3 # Cherry-pick range of conmits git cherry-pick conmita’..conmit2 # Cherry-pick without creating conmit git cherry-pick --no-conmit conmit-hash # Continue cherry-pick after resolving conflicts git cherry-pick --continue # Abort cherry-pick git cherry-pick --abort Advanced Reset & Clean bash # Reset to specific commit, keep changes staged git reset --soft conmit-hash # Reset to specific commit, unstage changes git reset --nixed connit-hash # Reset to specific commit, discard all changes git reset --hard conmit-hash # Clean untracked files (dry run) git clean -n # Clean untracked files git clean -f # Clean untracked files and directories git clean -fd # Clean including ignored files git clean -fx Bisect (Finding Bugs) bash ‘# Start bisecting git bisect start # Mark current commit as bad git bisect bad # Mark specific commit as good git bisect good comit-hash # Git will checkout middle conmit for testing # After testing, mark as good or bad git bisect good # on git bisect bad # Reset after finding the problenatic connit git bisect reset GitHub-Specific Commands GitHub CLI (gh) Commands bash # Install GitHub CLI first, then authenticate gh auth login # Clone repository gh repo clone usernane/repository-nane # Create new repository Bh repo create my-new-repo # Create private repository gh repo create my-new-repo --private # Fork a repository gh repo fork username/repasitory-name # View repository in browser gh repo view =-web # Create pull request gh pr create --title "My PR" --body "Description" # List pull requests gh pr list # View pull request gh pr view 123, # Checkout pull request Bh pr checkout 123 # Merge pull request gh pr merge 123 # Create issue gh issue create --title "Bug report" --body "Description" # List issues gh issue list # View issue gh issue view 123 Working with Pull Requests bash # Create feature branch git checkout -b feat e/new-feature # Make changes and commit git add . git commit -m "Add new feature" # Push branch git push -u origin feature/new-fe # Create pull request (using GitHub CLI) gh pr create --title "Add new feature" --body "This PR adds..." # Or create PR through web interface after pushing Useful Aliases & Configuration Common Git Aliases bash # Set up useful aliases git confi jloba git config --global alias.co checkout alias, t status git config --global elias. br branc git config --global alias.ci commit git config --global alias.unstage ‘reset HEAD -+' git =+global alias.last ‘log -1 HEAD" git config alias. visual 'Igitk’ git config alias.tree ‘log --graph --oneline --all git config bal alias.amend ‘conmit --amend --no-edit' # Now you can use short commands: git st # instead of git status git co main # instead of git checkout main git br # instead of git branch Quick Reference Workflow Daily Workflow bash #1, Start your day git pull 4 Get Latest changes # 2, Create feature branch git checkout -b feature/ny-feature # Create and switch to branch # 3, Make changes # ... edit files ... # 4, Stage and commit git add. # Stage changes git commit -m "Add my feature” —# Commit changes #5. Push and create PR git push -u origin feature/ny-feature # Push branch gh pr create # Create pull request #6, After PR is merged git checkout main # Switch to main git pull # Get Latest changes git branch -d feature/ny-feature # Delete Local branch Emergency Commands bash # Undo Last commit (keep changes) git # Undo Last commit (discard changes) git # Undo all uncommitted changes git # Recover deleted branch git # Find the commit hash git # Fix wrong commit message git "Correct message" s for Beginners 1. Always check status: Use (git_status) frequently to understand what's happening 2. Commit often: Make small, focused commits with clear messages 3, Use branches: Never work directly on main/master branch 4, Pull before push: Always (git pull) before (git push) to avoid conflicts 5. Write good commit messages: Be descriptive and use present tense 6. Use .gitignore: Add files you don't want to track (node_modules, .eny, etc) 7. Learn to read git output: Git provides helpful information in its messages 8. Practice with personal projects: Get comfortable with basic commands first 9. Don't panic: Most Git mistakes can be undone 10, Use GitHub Desktop or VS Code Git integration if command line feels overwhelming at first Remember: Git is powerful but can be complex. Start with basic commands and gradually work your way up to advanced features!

You might also like