30 Git Commands Every Developer Should Know
Certainly! Here’s an expanded list of 30 Git commands that every developer should know:
- git init: Initialize a new Git repository in the current directory.
- git clone [repository_url]: Clone a remote repository to your local machine.
- git add [file]: Stage a file for commit. Use “.” to stage all changes.
- git commit -m “[commit_message]”: Commit your staged changes with a descriptive message.
- git status: Check the status of your working directory and see which files are modified, staged, or untracked.
- git diff: Display the differences between your working directory and the last commit.
- git log: View the commit history, showing the author, date, and commit message.
- git branch: List all branches in your repository. The active branch is highlighted.
- git checkout [branch_name]: Switch to a different branch in your repository.
- git merge [branch_name]: Merge the changes from one branch into another.
- git pull: Fetch changes from a remote repository and merge them into your current branch.
- git push [remote_name] [branch_name]: Push your local changes to a remote repository.
- git remote -v: List all remote repositories associated with your local repository.
- git remote add [remote_name] [repository_url]: Add a new remote repository to your local repository.
- git stash: Temporarily save your changes without committing them, allowing you to switch branches or pull changes.
- git reset [file]: Unstage a file that you’ve added for commit.
- git revert [commit]: Create a new commit that undoes the changes introduced by a specific commit.
- git fetch: Download new changes from a remote repository without merging them.
- git tag [tag_name]: Create a new tag to mark a specific commit, often used for versioning.
- git rm [file]: Remove a file from the working directory and stage the deletion for commit.
- git show [commit]: Display information about a specific commit, including the changes introduced.
- git config –global user.name “[your_name]”: Configure your global Git username.
- git config –global user.email “[your_email]”: Configure your global Git email.
- git cherry-pick [commit]: Apply the changes introduced by a specific commit to your current branch.
- git remote remove [remote_name]: Remove a remote repository from your local repository.
- git rebase [branch]: Reapply commits from one branch on top of another, often used to maintain a linear commit history.
- git log –graph –oneline –all: Visualize the commit history in a compact graph format.
- git bisect: Use binary search to find the commit that introduced a bug.
- git blame [file]: Display the author and last modification for each line in a file.
- git config –global alias.[alias_name] “[command]”: Create custom Git aliases to shorten commonly used commands.
With these Git commands, you’ll have a solid foundation to effectively manage your codebase, collaborate with others, and maintain a clean version history.