Git
00 Basic Usage
## ------------------| Initialize Repository and Upload to GitHub
git init # Initialize a new Git repository.
git add . # Stage all files for commit.
git commit -m "message" # Commit changes with a message.
git remote add origin <URL> # Add a remote repository (replace <URL>).
git branch -M main # Set the default branch to main.
git push -u origin main # Push to the main branch for the first time.
## ------------------| Viewing Commit History
git log -p # Show commit history with diffs.
git show <hash> # Show details of a specific commit.
git reflog # Show a history of all changes to the HEAD.
git reset --hard # Reset the working directory to the latest commit, discarding all local changes.
git diff <hash> # Show changes introduced by a specific commit.
## ------------------| Basic Git Commands
git clone <repo> # Clone a repository
git add <file> # Stage a file for commit ( use . for add all files)
git status # Show the status of the working directory
git log # View commit history
git diff # Show unstaged changes
## ------------------| Branching & Merging
git branch # List branches
git branch <name> # Create a new branch
git checkout <branch> # Switch to a branch
git merge <branch> # Merge a branch into the current branch
git branch -d <branch> # Delete a branch
git stash # Save changes for later
git stash pop # Apply stashed changes
## ------------------| Remote Repositories
git remote -v # Show remote repositories
git remote add <name> <url> # Add a new remote repository
git push # Push changes to the remote repository
git pull # Fetch and merge changes from the remote repository
git fetch # Fetch changes without merging
git remote remove <name> # Remove a remote repository
## ------------------| Inspecting & Undoing
git reset --hard <commit> # Reset to a specific commit
git revert <commit> # Create a new commit to undo a previous commit
git clean -f # Remove untracked files
git reflog # Show the history of branch updates
git checkout <commit> # Switch to a specific commit
git rm <file> # Remove a file from the repository
## ------------------| Advanced Commands
git log --oneline # Short commit history
git diff --staged # Show staged changes
git cherry-pick <commit> # Apply a specific commit
git bisect start # Start a binary search to find a bug
git rebase <branch> # Reapply commits on top of another base
git blame <file> # Show who changed each line of a file
git tag <name> # Create a tag for a specific commit
git archive <branch> # Create an archive of the repository
git push --set-upstream origin <BranchName> # Set the upstream branch and push changes.
## ------------------| Miscellaneous
git gc # Cleanup unnecessary files
git fsck # Check for repository corruption
git shortlog # Summarize git log
git describe # Describe a commit using tags
git show <commit> # Show details about a specific commit
git diff-tree <commit> # Show changes in a commit 03. Other
03.1 Gitea
Last updated
