Git has revolutionized the way developers collaborate and manage their codebases. From tracking changes to facilitating teamwork, Git offers a plethora of commands and functionalities to streamline the development process. In this guide, we'll explore essential Git commands and their functionalities to empower you in mastering version control.
-
git fetch: Fetch changes from a remote repository without merging them.
-
git stash: Temporarily save uncommitted changes.
git stash apply: Apply the most recently stashed changes.
-
git remote: List remote repositories.
git remote add <name> <url>: Add a new remote repository.
-
git revert <commit>: Create a new commit that undoes the changes made in a specific commit, effectively reverting the repository to a previous state.
-
git reset: Reset the repository to a specific state.
git reset --soft <commit>: Move the branch pointer to the specified commit, keeping changes in the staging area.
git reset --mixed <commit>: Move the branch pointer to the specified commit, unstaging changes but keeping them in the working directory.
git reset --hard <commit>: Move the branch pointer to the specified commit, discarding all changes since that commit.
-
git cherry-pick <commit>: Apply the changes introduced by a specific commit to the current branch.
-
git rebase: Reapply commits on top of another base branch.
git rebase <branch>: Rebase the current branch onto the specified branch.
git rebase -i <commit>: Interactively rebase commits, allowing for squashing, reordering, or editing.
-
git tag: Create, list, or delete tags for specific commits.
git tag <tag-name>: Create a lightweight tag.
git tag -a <tag-name> -m "message": Create an annotated tag with a message.
git push --tags: Push tags to a remote repository.
-
git blame <file>: Show who last modified each line of a file and when.
-
git show <commit>: Display the details of a specific commit, including the changes made.
-
git config: Configure Git settings.
git config --global user.name "Your Name": Set your name globally.
git config --global user.email "your@email.com": Set your email globally.
git config --global core.editor "vim": Set the default text editor.
-
git remote: Manage remote repositories.
git remote -v: List remote repositories with their URLs.
git remote remove <remote>: Remove a remote repository.
-
git submodule: Manage submodules within a repository.
git submodule add <repository> <path>: Add a submodule to the repository.
git submodule update --init --recursive: Initialize and update submodules recursively.
-
git reflog: Display a log of all reference updates (branches, tags, etc.) in the repository.
-
git bisect: Use binary search to find the commit that introduced a bug.
git bisect start: Start the bisect process.
git bisect good <commit>: Mark a commit as good.
git bisect bad <commit>: Mark a commit as bad.