The Ultimate Git Command Guide: Streamline Your Development Workflow
Introduction
The Ultimate Git Command Guide: Streamline Your Development Workflow
Introduction
Git is a vital tool for developers, offering effective version control, teamwork, and project administration. Whether you’re solo or in a team, understanding Git commands is vital for smoothing your development process. This overview details the main Git commands you require, giving you a strong base for handling your code, monitoring alterations, and collaborating with fellow developers. Learning these commands can boost efficiency and maintain project momentum. Here are the essential Git commands every software engineer should master.
Configuration
1. git config — Configure Git settings, such as user name and email.
Example: git config --global user.name "Your Name"
2. git init — Initialize a new Git repository.
Example: git init
3. git clone
_Purpose: Clone an existing repository._
_Example: git clone_ [_https://github.com/user/repo.git_](https://github.com/user/repo.git)
4. git status
_Purpose: Show the working directory and staging area status._
_Example: git status_
5. git add
_Purpose: Add file contents to the index (staging area)._
_Example: git add . (add all files)_
6. git commit
_Purpose: Record changes to the repository._
_Example: git commit -m "Commit message"_
7. git push
_Purpose: Update remote refs along with associated objects._
_Example: git push origin main_
8. git pull
_Purpose: Fetch from and integrate with another repository or local branch._
_Example: git pull origin main_
9. git branch
_Purpose: List, create, or delete branches._
_Example: git branch new-branch (create new branch)_
10. git checkout
_Purpose: Switch branches or restore working tree files._
_Example: git checkout new-branch (switch to branch)_
11. git switch
_Purpose: Switch branches._
_Example: git switch new-branch_
12. git merge
_Purpose: Join two or more development histories together._
_Example: git merge new-branch (merge new-branch into current branch)_
13. git rebase
_Purpose: Reapply commits on top of another base tip._
_Example: git rebase main_
14. git log
_Purpose: Show commit logs._
_Example: git log --oneline_
15. git diff
_Purpose: Show changes between commits, commit and working tree, etc._
_Example: git diff (show unstaged changes)_
16. git show
_Purpose: Show various types of objects._
_Example: git show HEAD (show changes in the last commit)_
17. git stash
_Purpose: Stash the changes in a dirty working directory away._
_Example: git stash_
18. git stash pop
_Purpose: Apply the changes recorded in the stash to the working directory._
_Example: git stash pop_
19. git clean
_Purpose: Remove untracked files from the working directory._
_Example: git clean -fd_
20. git remote
_Purpose: Manage set of tracked repositories._
_Example: git remote add origin_ [_https://github.com/user/repo.git_](https://github.com/user/repo.git)
21. git fetch
_Purpose: Download objects and refs from another repository._
_Example: git fetch origin_
22. git remote -v
_Purpose: Show the URLs that a remote name corresponds to._
_Example: git remote -v_
23. git tag
_Purpose: Create, list, delete, or verify a tag object._
_Example: git tag -a v1.0 -m "Version 1.0"_
24. git push origin --tags
_Purpose: Push all tags to the remote repository._
_Example: git push origin --tags_
25. git reset
_Purpose: Reset current HEAD to the specified state._
_Example: git reset --hard HEAD~1 (reset to previous commit)_
26. git revert
_Purpose: Create a new commit that undoes the changes from a previous commit._
_Example: git revert HEAD_
27. git checkout --
_Purpose: Discard changes in the working directory._
_Example: git checkout -- file.txt (discard changes in file.txt)_
28. git cherry-pick
_Purpose: Apply the changes introduced by some existing commits._
_Example: git cherry-pick <commit-hash>_
29. git branch -d
_Purpose: Delete a branch._
_Example: git branch -d branch-name_
30. git branch -D
_Purpose: Force delete a branch._
_Example: git branch -D branch-name_
31. git merge --no-ff
_Purpose: Create a merge commit even when the merge resolves as a fast-forward._
_Example: git merge --no-ff new-branch_
32. git rebase -i
_Purpose: Start an interactive rebase._
_Example: git rebase -i HEAD~3_
33. git diff --staged
_Purpose: Show changes between the index and the last commit._
_Example: git diff --staged_
34. git blame
Purpose: Show what revision and author last modified each line of a file.
_Example: git blame file.txt_
35. git log --graph
_Purpose: Show a graph of the commit history._
_Example: git log --graph --oneline_
36. git reflog
_Purpose: Show a log of all references._
_Example: git reflog_
37. git stash list
_Purpose: List all stashes._
_Example: git stash list_
38. git stash apply
_Purpose: Apply a stash to the working directory._
_Example: git stash apply stash@{1}_
39. git stash drop
_Purpose: Remove a single stash entry from the list of stashes._
_Example: git stash drop stash@{1}_
40. git remote show
_Purpose: Show information about the remote repository._
_Example: git remote show origin_
41. git remote rm
_Purpose: Remove a remote._
_Example: git remote rm origin_
42. git pull --rebase
_Purpose: Fetch and rebase the current branch on top of the upstream branch._
_Example: git pull --rebase origin main_
43. git fetch --all
Purpose: Fetch all remotes.
_Example: git fetch --all_
44. git bisect
_Purpose: Use binary search to find the commit that introduced a bug._
_Example: git bisect start_
45. git submodule
_Purpose: Initialize, update, or inspect submodules._
_Example: git submodule update --init_
46. git archive
_Purpose: Create an archive of files from a named tree._
_Example: git archive --format=tar HEAD > archive.tar_
47. git shortlog
_Purpose: Summarize git log output._
_Example: git shortlog -s -n_
48. git describe
Purpose: Give an object a human-readable name based on an available ref.
Example: git describe --tags
49. git rev-parse
_Purpose: Parse revision (or other objects) and retrieve its hash._
_Example: git rev-parse HEAD_
50. git tag -d
_Purpose: Delete a tag from the local repository._
_Example: git tag -d v1.0_
51. git checkout -b
_Purpose: Create and switch to a new branch._
_Example: git checkout -b new-branch_
52. git push origin --delete
_Purpose: Delete a remote branch._
_Example: git push origin --delete branch-name_
53. git cherry
_Purpose: Find commits not merged upstream._
_Example: git cherry -v_
54. git rm
_Purpose: Remove files from the working tree and from the index._
_Example: git rm file.txt_
55. git mv
_Purpose: Move or rename a file, directory, or symlink._
_Example: git mv oldname.txt newname.txt_
56. git reset HEAD
_Purpose: Unstage changes._
_Example: git reset HEAD file.txt_
57. git log -p
_Purpose: Show changes over time for a specific file._
_Example: git log -p file.txt_
58. git diff --cached
_Purpose: Show changes between the index and the last commit (same as --staged)._
_Example: git diff --cached_
59. git apply
_Purpose: Apply a patch to files and/or to the index._
_Example: git apply patch.diff_
60. git format-patch
_Purpose: Prepare patches for e-mail submission._
_Example: git format-patch -1 HEAD_
61. git am
_Purpose: Apply a series of patches from a mailbox._
_Example: git am < patch.mbox_
62. git cherry-pick --continue
_Purpose: Resume cherry-picking after resolving conflicts._
_Example: git cherry-pick --continue_
63. git fsck
_Purpose: Verify the connectivity and validity of objects in the database._
_Example: git fsck_
64. git gc
_Purpose: Cleanup unnecessary files and optimize the local repository._
_Example: git gc_
65. git prune
_Purpose: Remove unreachable objects from the object database._
_Example: git prune_
66. git notes
_Purpose: Add or inspect object notes._
_Example: git notes add -m "Note message"_
67. git whatchanged
_Purpose: Show what changed, similar to git log._
_Example: git whatchanged_
68. git show-branch
_Purpose: Show branches and their commits._
_Example: git show-branch_
69. git verify-tag
_Purpose: Check the GPG signature of tags._
_Example: git verify-tag v1.0_
70. git show-ref
_Purpose: List references in a local repository._
_Example: git show-ref_
Twitter Account: Twitter
By Jatin Jain Saraf on July 9, 2024.