Commands

init

init --bare

Minimal - repo only.

Generally a .git is appended to the root directory name.

Has no working directory and the content of the .git directory is at the root directly.

add

add -A : include file deletions
add <path:at and underneath .>
add -u

All deletes.

reset

reset <path>
reset --hard

Removes from staging.

HEAD [~<n>]

N steps before HEAD.

Can be used to remove commits (also from origin).

Force push will be required.

HEAD [~<n>] <commit-hash>
<commit-hash> --soft

HEAD [~[n]].

Keep files in index (adds).

Commit.

-m ‘<name>’ [path]
--amend

Merge current changes with previous edit.

  • may cause loss of info.
  • do not amend public repos.
--no-edit

Do not offer to edit commit message.

Fetch.

  • --prune -- ??.

Clone - make a copy.

clone

[-b <branch].

clone <<url>.git> [target-directory <root-level> : also the new repo name]
config [ --global]

Username.

user.name "<>”

Email.

user.email “<>”

Show.

-l

Lists.

core.autocrlf <true|false>

Auto CR LF.

remote

remote -v

Shows origin.

add origin <>.git
add set-url origin <>.git

diff

[path].

update-index

Ignore (even if versioned).

--assume-unchanged [path]

.git/config.

Enable password caching.

config --global credential.helper osxkeychain

Commit.

--amend

Undo.

checkout

Select branch.

<file>

A particular file.

<file> <commit-hash>

Only changes in that commit.

In an empty directory will check-out those files.

  • -b <branch_name> -- Creates then checkout new branch.
<commit-hash> git checkout stash@{0} -- <filename>

clean

clean -d directories
clean -f ?files?
clean -i interactive

Deletes extra, i.e. unversioned files.

Branch.

()

Show the local branches.

<branch_name>

<branch_name> // to also reflect this push to origin :refs/tags/<tag_title>
-d

Deletes.

-D <branch>

Deletes branch locally.

-r

Show remote branch.

Exit.

Q.

(shift + q.

Log.

--oneline [branch]
--no-merges [branch]
cherry-pick
<hash>

push

push -f

Force.

Origin.

push <tag-name> | <branch-name>
<hash>:<branch>

Specific commit only.

Like one of the say two commits ahead of the origin/master.

<hash>:<branch> --set-upstream origin master
  • --tags -- All tags.

pull

pull <source: origin>
pull <source: branch>

Will overwrite irrespective of branch.

diff

diff HEAD^^ <file_path>

amend

Reset commit message.

git commit --amend
git commit --amend -m "New commit message"

Tracking branch

branch -vv

Shows remote tracking branch.

show

show stash@{0}:<path>

Display file content on screen.

revert

revert <path>

Record new commit to revert previous (usually a faulty one).

remote

remote -vv

Shows.

remote add <url>
remote set-url origin [push] <url>

remove

Origin.

rebase

rebase <commit>

Rebases current branch on to the referenced commit.

  • may cause loss of info.
  • do not rebase public repos.

rm

rm --cached

Keep local, delete only from git.

Removed.

Updated: 2026 Aug 19