Search...

Sunday, September 25, 2022

Git Config Cheat Sheet

$ git config --global user.name <name>
Define the author name to be used for all commits by the current user.
 
$ git config --global user.email<email>
Define the author email to be used for all commits by the current user.
 
$ git config --global alias. <alias-name> <git-command>
Create shortcut for a Git command. E.g. alias.glog log --graph --oneline will set git glog equivalent to git log --graph --oneline.
 
$ git config --system core.editor <editor> 
Set text editor used by commands for all users on the machine. arg should be the command that launches the desired editor (e.g., vi).
 
$ git config --global --edit

Git Log Cheat Sheet

$ git log -<limit>
Limit number of commits by . E.g. git log -5 will limit to 5 commits.
 
$ git log --oneline
Condense each commit to a single line.
 
$ git log -p
Display the full diff of each commit.
 
$ git log --stat
Include which files were altered and the relative number of lines that were added or deleted from each of them.
 
$ git log --author= "<pattern>"
Search for commits by a particular author.
 
$ git log --grep="<pattern>"
Search for commits with a commit message that matches .
 
$ git log <since>..<until>
Show commits that occur between and . Args can be a commit ID, branch name, HEAD, or any other kind of revision reference.
 
$ git log -- <file>
Only display commits that have the specified file.
 
$ git log --graph --decorate
--graph flag draws a text based graph of commits on left side of commit msgs. --decorate adds names of branches or tags of commits shown.

Remote Repositories Cheat Sheet

$ git remote add <name> <url>
Create a new connection to a remote repo. After adding a remote, you can use as a shortcut for in other commands.
 
$ git fetch <remote> <branch>
Fetches a specific , from the repo. Leave off to fetch all remote refs.
 
$ git pull <remote>
Fetch the specified remote’s copy of current branch and immediately merge it into the local copy.
 
$ git push <remote> <branch>
Push the branch to , along with necessary commits and objects. Creates named branch in the remote repo if it doesn’t exist.