It contains all commonly and uncommonly used git commands with explanation.
Table of Contents:
- Setup and Configuration
- Creating and Initializing Repositories
- Staging and Committing Changes
- Viewing Changes and Logs
- Branching and Merging
- Remote Repositories
- Tagging
- Undoing Changes
- Stashing Changes
- Advanced Operations
- Collaboration and Contributing
- Sets the username for all repositories on your machine.
git config --global user.name "Your Name"
- Sets the email for all repositories on your machine.
git config --global user.email "you@example.com"
- Displays all configuration settings.
git config --list
- Sets the default text editor for Git (e.g., vim, nano).
git config --global core.editor <editor>
- Creates a shortcut for a Git command.
git config --global alias.<alias-name> <command>
- Initializes a new Git repository in the current directory.
git init
- Creates a local copy of a remote repository.
git clone <repository-url>
- Adds a file to the staging area.
git add <file>
- Adds all changes in the current directory to the staging area.
git add .
- Creates a commit with the specified message.
git commit -m "Commit message"
- Stages and commits all tracked files in one step.
git commit -a -m "Commit message"
- Unstages a file from the staging area.
git restore --staged <file>
- Displays the status of files in the working directory and staging area.
git status
- Shows differences between the working directory and the staging area.
git diff
- Shows differences between the staging area and the last commit.
git diff --staged
- Displays a history of commits.
git log
- Shows a condensed commit history.
git log --oneline
- Displays details of a specific commit.
git show <commit-hash>
- Lists all branches in the repository.
git branch
- Creates a new branch.
git branch <branch-name>
- Switches to the specified branch.
git checkout <branch-name>
- Another way to switch branches.
git switch <branch-name>
- Creates and switches to a new branch.
git checkout -b <branch-name>
- Merges the specified branch into the current branch.
git merge <branch-name>
- Deletes the specified branch.
git branch -d <branch-name>
- Links a local repository to a remote repository.
git remote add origin <url>
- Lists remote connections.
git remote -v
- Pushes commits from the local branch to the remote branch.
git push origin <branch-name>
- Fetches changes from the remote repository without merging them.
git fetch
- Fetches and merges changes from the remote repository.
git pull
- Pushes a new branch and sets it to track the remote branch.
git push --set-upstream origin <branch-name>
- Creates a lightweight tag for the current commit.
git tag <tag-name>
- Creates an annotated tag.
git tag -a <tag-name> -m "Message"
- Displays details about a tag.
git show <tag-name>
- Pushes a tag to the remote repository.
git push origin <tag-name>
- Pushes all tags to the remote repository.
git push --tags
- Restores a file to its last committed state.
git restore <file>
- Resets the current branch to the specified commit.
git reset <commit>
- Resets to the commit but keeps changes staged.
git reset --soft <commit>
- Resets to the commit and removes all changes.
git reset --hard <commit>
- Creates a new commit that undoes the changes from a specific commit.
git revert <commit>
- Temporarily saves changes without committing them.
git stash
- Lists all stashes.
git stash list
- Applies a specific stash.
git stash apply <stash>
- Applies and removes the most recent stash.
git stash pop
- Deletes a specific stash.
git stash drop <stash>
- Applies a specific commit to the current branch.
git cherry-pick <commit>
- Moves the base of the current branch to the specified branch.
git rebase <branch-name>
- Displays a log of all reference updates (useful for recovery).
git reflog
- Helps identify the commit that introduced a bug.
git bisect
- Creates a personal copy of a repository on GitHub or similar platforms.
git fork
- Fetches changes from the original repository of a fork.
git fetch upstream
- Replays local commits on top of the upstream branch.
git rebase upstream/<branch>
Created By Kausalya N P
Users can copy this repo for educational purpose.