Skip to main content

Git Commands Cheat Sheet

 Here are some basic Git commands:

Commands 

Description

git add <file>Adds a specific file to the staging area.
git add . or git add –allAdds all modified and new files to the staging area.
git statusShows the current state of your repository, including tracked and untracked files, modified files, and branch information.
git status –ignoredDisplays ignored files in addition to the regular status output.
git diffShows the changes between the working directory and the staging area (index).
git diff <commit1> <commit2>Displays the differences between two commits.
git diff –staged or git diff –cachedDisplays the changes between the staging area (index) and the last commit.
git diff HEADDisplay the difference between the current directory and the last commit
git commitCreates a new commit with the changes in the staging area and opens the default text editor for adding a commit message.
git commit -m “<message>” or git commit –message “<message>”Creates a new commit with the changes in the staging area and specifies the commit message inline.
git commit -a or git commit –allCommits all modified and deleted files in the repository without explicitly using git add to stage the changes.
git notes addCreates a new note and associates it with an object (commit, tag, etc.).
git restore <file>Restores the file in the working directory to its state in the last commit.
git reset <commit>Moves the branch pointer to a specified commit, resetting the staging area and the working directory to match the specified commit.
git reset –soft <commit>Moves the branch pointer to a specified commit, preserving the changes in the staging area and the working directory.
git reset –hard <commit>Moves the branch pointer to a specified commit, discarding all changes in the staging area and the working directory, effectively resetting the repository to the specified commit.
git rm <file>Removes a file from both the working directory and the repository, staging the deletion.
git mvMoves or renames a file or directory in your Git repository.


Git Commit (Updated Commands)

Here are some of the updated commands for Git commit:

Commands 

Description

git commit -m “feat: message”Create a new commit in a Git repository with a specific message to indicate a new feature commit in the repository.
git commit -m “fix: message”Create a new commit in a Git repository with a specific message to fix the bugs in codebases
git commit -m “chore: message”Create a new commit in a Git repository with a specific message to show routine tasks or maintenance.
git commit -m “refactor: message”Create a new commit in a Git repository with a specific message to change the code base and improve the structure.
git commit -m “docs: message”Create a new commit in a Git repository with a specific message to change the documentation.
git commit -m “style: message”Create a new commit in a Git repository with a specific message to change the styling and formatting of the codebase.
git commit -m “test: message”Create a new commit in a Git repository with a specific message to indicate test-related changes.
git commit -m “perf: message”Create a new commit in a Git repository with a specific message to indicate performance-related changes.
git commit -m “ci: message”Create a new commit in a Git repository with a specific message to indicate the continuous integration (CI) system-related changes.
git commit -m “build: message”Create a new commit in a Git repository with a specific message to indicate the changes related to the build process.
git commit -m “revert: message”Create a new commit in a Git repository with a specific message to indicate the changes related to revert a previous commit.

Branching and Merging

Here are some Git branching and merging commands:

Commands 

Description

git branchLists all branches in the repository.
git branch <branch-name>Creates a new branch with the specified name.
git branch -d <branch-name>Deletes the specified branch.
git branch -aLists all local and remote branches.
git branch -rLists all remote branches.
git checkout <branch-name>Switches to the specified branch.
git checkout -b <new-branch-name>Creates a new branch and switches to it.
git checkout — <file>Discards changes made to the specified file and revert it to the version in the last commit.
git merge <branch>Merges the specified branch into the current branch.
git logDisplays the commit history of the current branch.
git log <branch-dDisplays the commit history of the specified branch.
git log –follow <file>Displays the commit history of a file, including its renames.
git log –allDisplays the commit history of all branches.
git stashStashes the changes in the working directory, allowing you to switch to a different branch or commit without committing the changes.
git stash listLists all stashes in the repository.
git stash popApplies and removes the most recent stash from the stash list.
git stash dropRemoves the most recent stash from the stash list.
git tagLists all tags in the repository.
git tag <tag-name>Creates a lightweight tag at the current commit.
git tag <tag-name> <commit>Creates a lightweight tag at the specified commit.
git tag -a <tag-name> -m “<message>”Creates an annotated tag at the current commit with a custom message.

Remote Repositories

Here are some Git remote repositories commands:

Commands 

Description

git fetchRetrieves change from a remote repository, including new branches and commit.
git fetch <remote>Retrieves change from the specified remote repository.
git fetch –pruneRemoves any remote-tracking branches that no longer exist on the remote repository.
git pullFetches changes from the remote repository and merges them into the current branch.
git pull <remote>Fetches changes from the specified remote repository and merges them into the current branch.
git pull –rebaseFetches changes from the remote repository and rebases the current branch onto the updated branch.
git pushPushes local commits to the remote repository.
git push <remote>Pushes local commits to the specified remote repository.
git push <remote> <branch>Pushes local commits to the specified branch of the remote repository.
git push –allPushes all branches to the remote repository.
git remoteLists all remote repositories.
git remote add <name> <url>Adds a new remote repository with the specified name and URL.

Git Comparison

Here are some Git comparison commands:

Commands 

Description

git showShows the details of a specific commit, including its changes.
git show <commit>Shows the details of the specified commit, including its changes.

Git Managing History

Here are some Git managing history commands:

Commands 

Description

git revert <commit>Creates a new commit that undoes the changes introduced by the specified commit.
git revert –no-commit <commit>Undoes the changes introduced by the specified commit, but does not create a new commit.
git rebase <branch>Reapplies commits on the current branch onto the tip of the specified branch.

Comments

Popular Posts

TechBytes on Linux

This is a growing list of Linux commands which might come handy for the newbies of Linux. 1. Found out i had to set the date like this:    # date -s 2007.04.08-22:46+0000 2. Mounting     sudo mount -t cifs // < pingable_host_or_ip > / < win_share_name > /build -o user= ,domain= ,uid=string,gid=string 3. To install linux packages from internet (ubuntu only)     apt-get install 4. To determine what ports the machine is currently listening on     netstat -an | grep -i listen | less 5. Find in files in Linux     find . | xargs grep 'string' -sl 6. To become superuser/root     sudo -i 7. To find a running process using name ps -aef | grep "searchstring" 8. Alt + F2 opens run window in RHEL 9. To access windows share from linux smb:// /d$ 10. To know the last reboot date & time $ last reboot | head -1 11. To install RPM packages in RHEL rpm -ivh 12. To un-install RPM package in RHEL rpm -e 13. To display Linux Kerne

How to change the default pdf viewer application in your Mac or MacBook

  To  set  a  PDF viewer  as the  default  on  Mac  OS X: Select any  PDF  file from Finder. Control-click to open the menu. ...  Choose Get Info from the menu that opens. ...  From the Open with: section in the new window that opens, select your preferred application, such as Adobe  Reader  or Preview. ...  Click the  Change  All button.

ಮ್ಯಾಕ್ ಬುಕ್ ಮತ್ತು ವಿನ್ಡೋಸ್ ಲ್ಯಾಪ್ ಟಾಪ್ ನಲ್ಲಿ ಎಲ್ಲ ಆಪ್ ಗಳಲ್ಲಿ ಕನ್ನಡ ಟೈಪ್ ಮಾಡುವುದು ಹೇಗೆ ?? How to type kannada on any app in Mac OS and Windows laptops

 ಮ್ಯಾಕ್ ಬುಕ್ ನಲ್ಲಿ ಕನ್ನಡ ದಲ್ಲಿ ಟೈಪ್ ಮಾಡಲು ಲಿಪಿಕ ಎನ್ನುವ ಈ ಕೆಳಗಿನ ಲಿಂಕ್ ಅನ್ನು ಕ್ಲಿಕ್ ಮಾಡಿ .pkg ಫೈಲ್ ಅನ್ನು ಡೌನ್ ಲೋಡ್ ಮಾಡಿ ಅದನ್ನು ಇನ್ಸ್ತಾಲ್ ಮಾಡಿಕೊಳ್ಳಿ. ಇನ್ಸ್ತಾಲ್ ಮಾಡಿದ ಮೇಲೆ ಅಪ್ಪ್  ಅನ್ನು ಒಪೆನ್ ಮಾಡಿ.    ಲಿಪಿಕಾ ಆಪ್    ಟಾಸ್ಕ್  ಬಾರ್ ನಲ್ಲಿ 'A' ಎನ್ನುವ ಐಕಾನ್ ಅನ್ನು ಕ್ಲಿಕ್ ಮಾಡಿ. ಲಿಪಿಕಾ ಐಮ್ಈ ಅನ್ನು ಕ್ಲಿಕ್ ಮಾಡಿ. ಕನ್ನಡ ಭಾಷೆಯನ್ನು ಆಯ್ಕೆ ಮಾಡಿ.  ಆ ನಂತರ ಯಾವುದೇ ಮ್ಯಾಕ್ OS ಆಪ್ ನಲ್ಲಿ ನೀವು  ಕನ್ನಡದಲ್ಲಿ ಟೈಪ್ ಮಾಡಬಹುದು.  ಕೇವಲ ಕ್ರೊಮ್ ವೆಬ್ ಬ್ರೌಸರ್ ನಲ್ಲಿ ನಿಮಗೆ ಕನ್ನಡ ಟೈಪ್ ಮಾಡಬೇಕಾದಲ್ಲಿ ಈ ಕೆಳಗಿನ ಲಿಂಕ್ ಅನ್ನು ಕ್ಲಿಕ್ ಮಾಡಿ  ಗೂಗಲ್ ಇನ್ಪುಟ್ ಮೆಥಡ್  (Google Input Method) ಗೂಗಲ್ ಕ್ರೊಮ್ ಎಕ್ಸ್ ಟೆನ್ಷನ್ ಅನ್ನು ಇನ್ಸ್ತಾಲ್ ಮಾಡಿಕೊಳ್ಳಿ. ಅದನ್ನು ಒಪೆನ್ ಮಾಡಿ ಕನ್ನಡ ಭಾಷೆ ಯನ್ನು ಆಡ್ ಮಾಡಿಕೊಳ್ಳಿ.  ವೆಬ್ ಬ್ರೌಸರ್ ನಲ್ಲಿ ನಿಮಗೆ ಕನ್ನಡ ಟೈಪ್ ಮಾಡಬೇಕಾದಲ್ಲಿ ಈ ನೀಲಿ ಕೀ ಬೋರ್ಡ್ ಐಕಾನ್ ಅನ್ನು ಬುಕ್ಮಾರ್ಕ್ ಬಾರ್ ನಲ್ಲಿ ಕ್ಲಿಕ್ ಮಾಡಿ ಕನ್ನಡ ಫೊನೆಟಿಕ್ ಆಪ್ಷನ್ ಅನ್ನು ಆಯ್ಕೆ ಮಾಡಿ.  ಕನ್ನಡ ಟೈಪಿಂಗ್ ಅನ್ನು ಮ್ಯಾಕ್ ಬುಕ್ ಮತ್ತು ವಿನ್ಡೋಸ್ ಲ್ಯಾಪ್ ಟಾಪ್ ಬ್ರೌಸರ್ ನಲ್ಲಿ ಆನಂದಿಸಿ.  ಮೈಕ್ರೊಸಾಫ್ಟ್  ವಿನ್ಡೋಸ್ ನಲ್ಲಿ ಯಾವ ಆಪ್ ನಲ್ಲಿ ಬೇಕಾದರೂ ಕನ್ನಡ ಟೈಪ್ ಮಾಡಲು ನಿಮಗೆ ಎರಡು ಆಯ್ಕೆ ಇವೆ: ೧. ಫೊನೆಟಿಕ್ ಕನ್ನಡ ಟೈಪ್ ಮಾಡಲು