--- stage: Create group: Source Code info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments" --- # Frequently used Git commands **(FREE ALL)** The following commands are frequently used. ## Add another URL to a remote Add another URL to a remote, so both remotes get updated on each push: ```shell git remote set-url --add ``` ## Refs and Log ### Use reflog to show the log of reference changes to HEAD ```shell git reflog ``` ### Check the Git history of a file The basic command to check the Git history of a file: ```shell git log ``` If you get this error message: ```plaintext fatal: ambiguous argument : unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: ``` Use this to check the Git history of the file: ```shell git log -- ``` ### Check the content of each change to a file ```shell gitk ``` ### Check the content of each change to a file, follows it past file renames ```shell gitk --follow ``` ## Debugging ### Use a custom SSH key for a Git command ```shell GIT_SSH_COMMAND="ssh -i ~/.ssh/gitlabadmin" git ``` ### Debug cloning With SSH: ```shell GIT_SSH_COMMAND="ssh -vvv" git clone ``` With HTTPS: ```shell GIT_TRACE_PACKET=1 GIT_TRACE=2 GIT_CURL_VERBOSE=1 git clone ``` ### Debugging with Git embedded traces Git includes a complete set of [traces for debugging Git commands](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_debugging), for example: - `GIT_TRACE_PERFORMANCE=1`: enables tracing of performance data, showing how long each particular `git` invocation takes. - `GIT_TRACE_SETUP=1`: enables tracing of what `git` is discovering about the repository and environment it's interacting with. - `GIT_TRACE_PACKET=1`: enables packet-level tracing for network operations. ## Rebasing ### Rebase your branch onto the default The `-i` flag stands for 'interactive'. Replace `` with the name of your [default branch](../../user/project/repository/branches/default.md): ```shell git rebase -i ``` ### Continue the rebase if paused ```shell git rebase --continue ``` ### Use `git rerere` To _reuse_ recorded solutions to the same problems when repeated: ```shell git rerere ``` To enable `rerere` functionality: ```shell git config --global rerere.enabled true ```