Skip to content

Git Commands

VinhPham2106 edited this page Oct 3, 2023 · 3 revisions
  • ls: This command lists the files and directories in the current directory.

  • du -sh: This command displays the disk usage summary of the current directory. The -s option stands for "summarize," and the -h option stands for "human-readable," which formats the output in a more readable format (e.g., in kilobytes, megabytes, etc.).

  • du -sh <directory-name>: This command displays the disk usage summary of the directory in a human-readable format. It shows the total size occupied by the specified directory and its contents.

  • rm -rf <directory-name>: This command forcefully removes the directory and all its contents (-r stands for recursive, and -f stands for force). Please be sure to use caution as it permanently deletes files and directories.

  • git clone <git-url>: This command clones a Git repository from the specified URL <git-url> into the current directory. It creates a working copy of the repository.

  • git clone --branch <name>: This option is used with the git clone command to specify a particular branch, tag, or commit from the cloned repository to be the initial state of the new repository. Instead of defaulting to the branch that the cloned repository's HEAD is pointing to, this option allows you to choose a specific branch, tag, or commit as the starting point for the newly created repository. If used in a non-bare repository (one with a working directory), the specified branch will be checked out, making it the active branch you can work on. Additionally, you can use this option to detach the HEAD at a specific commit, effectively creating a new branchless state for the resulting repository.

  • git clone --bare <git-url>: This Git command is used to create a bare clone of a Git repository from the specified <git-url>. A bare clone is a particular type of repository that does not have a working directory, making it suitable for use as a central or remote repository in a collaborative Git workflow. It contains only the Git data and history, allowing for efficient storage and sharing of code changes among team members or remote servers.

  • git clone --depth=<depth> <repository-url>: This command is similar to a standard "git clone" but allows you to specify the depth, which determines how many commit histories are fetched from the remote repository. The depth parameter helps control the amount of historical data retrieved, which is useful for faster cloning of repositories with extensive histories.

  • git clone --depth=<depth> --bare <repository-url>: This command is similar to the previous "git clone" command but creates a bare Git repository with limited depth. A bare repository contains only Git data and history without a working directory. The <depth> parameter determines how many recent commits are included in the history of the bare repository. This is particularly useful for creating lightweight, read-only copies of repositories with reduced commit history for sharing or archival purposes.

  • tree: This command displays a hierarchical tree structure of the files and directories in the current directory, providing a visual representation of the directory structure.

  • git worktree add <git-directory-name>: This Git command creates a new linked working directory, also known as a "worktree," for an existing Git repository. The <git-directory-name> parameter specifies the name of the subdirectory where the new working directory will be created. Worktrees allows you to work on multiple branches or states of the same Git repository simultaneously, each in its isolated working directory. This is particularly useful for tasks that require separate environments, such as testing, bug fixing, or experimenting with different branches, without affecting the main repository's state.

  • git log: This command displays the commit history of the current branch in the Git repository, showing commit messages, authors, dates, and commit hashes.

  • git log --after=<date>: This command displays the commit history of the current branch, filtering and showing only the commits made after the specified date. It helps examine changes made on or after a specific date in the Git repository.

  • git log --oneline | wc -l: This command generates a concise one-line summary of commit messages in the current branch and then uses a command to count the number of lines, indicating the total count of commits in the branch. It's a quick way to determine the commit count.

  • git log --after=<date> --oneline | wc -l: This command combines date-based filtering with the one-line summary format and counts the lines, giving you the total count of commits made on or after the specified date in the current branch. It's useful for getting a specific count of commits within a date range.

  • git fetch: This command fetches changes from a remote Git repository, updating your local references to remote branches. It doesn't automatically merge or rebase those changes into your current branch.

  • git fetch -a: This command fetches changes from all remote repositories configured in your Git configuration.

  • git fetch origin master: This command fetches changes from the "master" branch of the remote repository named "origin" and updates the corresponding remote tracking branch in your local repository.

  • sloccount --duplicates --follow --details : This command counts the number of source lines of code (SLOC) of a given file or directory. The "duplicate" option includes duplicated files, the "follow" options instructs sloccount to follow symbolic links, and the "detail" option provides breakdown of the count by languages.

  • sloccount --filecount --duplicates --follow --details : This command shows the number of files sorted by languages, with duplicated files included and symbolic links followed or a given file or directory.

  • cloc --follow-links --skip-uniqueness : This command shows a summary table of the used languages, number of blank, comment and code lines of a given file or directory.

  • cloc --by-file --follow-links --skip-uniqueness : This command shows a summary table of the files, number of blank, comment and code lines of a given file or directory.

Clone this wiki locally