Skip to content

Instantly share code, notes, and snippets.

@leslie-leder
Last active March 21, 2023 09:23
Show Gist options
  • Save leslie-leder/e48641bbd9506c9ac88f to your computer and use it in GitHub Desktop.
Save leslie-leder/e48641bbd9506c9ac88f to your computer and use it in GitHub Desktop.
Git Cheat Sheet

Config

Git Global User Name

git config --global user.name "Any User"

Git Repository User Name

git config user.name "Any User"

Show remote url

git config --get remote.${REMOTE}.url

git ls-remote --get-url ${REMOTE}

git remote -v

git remote show ${REMOTE}

Add & fetch remote branch without clone but tracking

git remote add -t $RemoteBranchName -f $RemoteNameInTheLocalRepo $RemoteRepoUrl

Fetch remote branch without clone

git fetch $RemoteName +$RemoteBranch:${LocalBranchNameLocatedIn:refs/heads}

git fetch $RemoteName +$RemoteBranch

Change remote url

git remote set-url origin $RepositoryUrl

List remote refs

git ls-remote $RepositoryUrl

Git incoming log (master)

git log origin/master ^master

Git outgoing log (master)

git log master ^origin/master

Git log graph

git log --oneline --graph --decorate

Git show current branch

git symbolic-ref HEAD

git symbolic-ref HEAD --short

Revert local changes

Revert changes to the working copy.

git checkout .

Revert changes to the index (i.e. add).

git reset

Revert committed changes.

git revert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment