𝟏. 𝐀𝐝𝐝/𝐂𝐨𝐦𝐦𝐢𝐭𝐀𝐥𝐥
Default way: git add.
git commit -m “message”
Different: git commit -a -m “message”
𝟐. 𝐀𝐥𝐢𝐚𝐬𝐞𝐬
Using aliases, you can write your own Git commands to do whatever you want.
Example: git config –global alias.ac ‘!git add -A && git commit -m’
(aliased to ac, git add -A && git commit -m does a full add and commit)
𝟑. 𝐑𝐞𝐯𝐞𝐫𝐭
We can easily undo any commit on the current branch using the revert command.
Example: git revert 486bdb2
Another way: git revert HEAD (for the most recent commit)
𝟒. 𝐑𝐞𝐟𝐥𝐨𝐠
This command allows you to easily view the latest commits, pull, reset, push, etc. on your local machine.
Example: Git Relogin
𝟓. 𝐏𝐫𝐞𝐭𝐭𝐲𝐋𝐨𝐠𝐬
Gives you the option to print out a nice log of your commits/branches.
Example: git log –graph –decorate –oneline
𝟓. 𝐏𝐫𝐞𝐭𝐭𝐲𝐋𝐨𝐠𝐬
Gives you the option to print out a nice log of your commits/branches.
Example: git log –graph –decorate –oneline
𝟔. 𝐒𝐞𝐚𝐫𝐜𝐡𝐢𝐧𝐠𝐋𝐨𝐠𝐬
You can also use the log command to search for specific changes in your code.
Example: git log -S “commits in JavaScript are very similar”
𝟕. 𝐒𝐭𝐚𝐬𝐡
This command saves (stores them locally) all code changes, but doesn’t actually commit them.
Example: git storage
𝟖. 𝐑𝐞𝐦𝐨𝐯𝐞 𝐃𝐞𝐚𝐝 𝐁𝐫𝐚𝐧𝐜𝐡𝐞𝐬
This command deletes all tracking information on the local computer for branches that are not in the remote repository but does not delete local branches.
Example: git remote update –prune
𝟗. 𝐁𝐢𝐬𝐞𝐜𝐭
Find out which commits caused a particular bug
Example: git bisect start
git half broken
git bisect 48c86d6
𝟏𝟎. 𝐃𝐞𝐬𝐭𝐫𝐨𝐲𝐋𝐨𝐜𝐚𝐥𝐂𝐡𝐚𝐧𝐠𝐞𝐬
It is possible to refresh all changes in the local branch to the exact contents in the remote branch.
Example: git reset –hard origin/main