Git is a popular version control system that allows you to track changes in your codebase, collaborate with others, and manage your project’s history. Here is a list of Git commands from basic to advanced:
Basic Git Commands:
- git init: Initializes a new Git repository in the current directory.
- git clone <repository URL>: Creates a copy of a remote Git repository on your local machine.
- git add <file(s)>: Stages changes for commit.
- git commit -m “commit message”: Records staged changes with a descriptive message.
- git status: Shows the status of your working directory and staged changes.
- git log: Displays a history of commits.
- git diff: Shows the differences between the working directory and the last commit.
Branching and Merging:
- git branch: Lists all branches in your repository.
- git branch <branch_name>: Creates a new branch.
- git checkout <branch_name>: Switches to a different branch.
- git merge <branch_name>: Merges changes from one branch into the current branch.
- git pull: Fetches changes from a remote repository and merges them into the current branch.
Remote Repositories:
- git remote -v: Lists remote repositories.
- git remote add <name> <URL>: Adds a remote repository.
- git push <remote> <branch>: Pushes your changes to a remote repository.
- git fetch <remote>: Retrieves changes from a remote repository.
- git pull <remote> <branch>: Fetches and merges changes from a remote repository.
Working with Stashes:
- git stash: Temporarily saves changes that are not ready to be committed.
- git stash pop: Applies the most recent stash and removes it.
- git stash list: Lists all stashes.
Advanced Git Commands:
- git rebase <branch_name>: Reapplies changes from one branch on top of another.
- git cherry-pick <commit>: Applies a specific commit to the current branch.
- git reset <commit>: Moves the branch pointer to a specific commit.
- git reflog: Shows a log of all Git references.
- git submodule: Manages Git submodules within a repository.
- git bisect: Helps find a specific commit that introduced a bug.
- git filter-branch: Rewrites the repository history using a script.
- git remote show <remote>: Displays detailed information about a remote repository.
- git blame <file>: Shows the author and revision for each line in a file.
- git log –graph –oneline –all: Visualizes the branch history graph.