Useful Commands

Useful Commands#

This is a selection of commands that can particularly enhance your experience with :

git status  

Displays information about:

  • How your current branch compares to its reference branch(es).

  • The status of the workspace:

    • What files have changed and are staged,

    • What files changed and are unstaged.

  • Commands you might want to run.

Note

git status can be particularly useful wenn running a rebase during which you have to step through all rebased commits.

git log  

git log is an extremely powerful tool to explore the history of a repository with some particularly useful option:

  • --oneline shows a condensed view with each commit on a single line.

  • --graph visualizes the commit history as a branching graph.

  • --author="Author Name" shows commits made by a specific author.

  • --since="2 weeks ago" displays commits made since a specific date, useful for reviewing recent changes.

  • -p displays the patch (diff) introduced in each commit, allowing you to see what changes were made.

  • --grep="keyword" filters commits to show only those with messages containing a specific keyword.

git reflog  

Displays the git reference log.

It can be used to get the references of previous stages, including those that did not make it into the history.

git rebase -i 

With git rebase -i you can rewrite the history of a single branch (see the Rewriting History). In particular you can clean up a history by squashing several commits into a single commit.

It can be used to get the references of previous stages, including those that did not make it into the history.

git stash  

This command allow you to “put unstaged changes away” such that you can perform operations on your workspace, such as git pull, that would otherwise overwrite files you changed but did not yet add to the stage.

Note

git stash pop will reapply the changes you had put away.

git cherry-pick  

git cherry-pick <commit> will apply the changes introduced in <commit> to the current branch.