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.