Essential GIT Commands & Tips

save time and prevent mistakes

Scribbled Arrow

add

git add --patch

git add -p

short

This GIT option allows you to make more specific commit

It provides interactive review of chunks of changes that you can add, split into smaller chunks, or ignore

Scribbled Underline 2
Scribbled Arrow

amend

git commit --amend

If you miss an important file in your last commit, we can use this command to fix the issue

You can use the git commit –-amend command to edit a commit message but first add the files you want to include

Scribbled Underline 2
Scribbled Arrow

bisect

git-bisect

This command is used to discover the commit that has introduced a bug in the code

When you find a regression, something broken that used to work, use git -bisect to find the commit that broke it

Scribbled Underline 2
Scribbled Arrow

blame

git blame

You can ignore changes made by the revision when assigning blame, as if the change never happened

This command shows what revision and author last modified each line of a file

Scribbled Underline 2
Scribbled Arrow

status

git status

This command is a life saver when working with many files

The git status command displays the state of the working directory and the staging area

Scribbled Underline 2
Scribbled Arrow

checkout

git checkout -

This GIT command  allows you to change to the previous branch

Be careful with your staged files and commits when switching between branches

Scribbled Underline 2
Scribbled Arrow

diff

git diff --staged

This command allows us to track the changes that are staged but not committed

It shows changes between commits, commit and working tree, etc

Scribbled Underline 2
Scribbled Arrow
Scribbled Arrow

update-index

git update-index

This command will register file contents in the working tree to the index

Each file mentioned is updated into the index and any unmerged or needs updating state is cleared

Scribbled Underline 2
Scribbled Arrow

worktree

git-worktree

This GIT option allows managing multiple working trees

With git worktree add a new working tree is associated with the repository along with additional metadata that differentiates that working tree from others in the same repository

Scribbled Underline 2
Scribbled Arrow

Credits

https://git-scm.com/

https://unsplash.com/