commands to be executed in the repository directory or any of its subdirectories
copy a repository git clone http://gitserver/myrepository list current changes git status add changes to the transaction git add myfile ... git add --all create a commit git commit show history git log get all new changes from a remote git fetch get and merge all new changes from the remote of the current branch git pull list registered remote repositories git remote add a new remote git remote add myremotename http://myrepository list local branches git branch list remote branches git branch -r create a new branch git checkout -b mybranch checkout an existing branch git checkout mybranch checkout an old state git checkout mycommit reset only one specific file to the last commit git checkout myfile merge another branch into the current branch git merge mybranch pull from another branch git pull mybranch push to another remote git push myremote show file content differences git diff show differences for a specific myfile git diff -- myfile show differences for a specific file at specific branch or commit git diff mybranch -- file show differences to a specific commit git diff mycommit remove uncommitted changes only from the index git reset delete uncommitted changes completely and permanently git reset --hard tag the current commit git tag add mytag sync your local tags with the remote git push --tags fetch force pushed branch git fetch && git reset origin/master --hard change/edit remote url git remote set-url myurl change/rewrite/edit commit messages git rebase -i HEAD~3 checkout the previously used branch git checkout - checkout one file to specific commit git checkout mybranch -- path
add a submodule git submodule add http://gitserver/repositoryname download submodule contents git update rename or move a submodule git mv a b merge a single commit from another branch git cherry-pick commit-id reset to remote state git reset --hard origin/mybranch delete last commit and sync with remote git reset HEAD^ --hard git push origin -f uncommit the most recent commit git reset --soft HEAD^ create a new commit that reverts to the state at an old commit git revert copy all files to a tar archive without the .git directory and without files that match .gitignore git archive mybranch mydestination.tar delete a remote tag git push origin --delete mytag delete a remote branch git push origin --delete mybranch create a new database-only git repository git init --bare delete local branches that do not exist on remote git remote prune origin remove untracked and ignored files git clean -fX export zip without .git directory git archive main --prefix directory-name --output /tmp/name.zip rename local branch git branch -m myoldname mynewname move tag git tag -f mynewtagname remove submodule git rm find all commits that changed a file git log myfilename remove branches without remote counterpart git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "\", $1); print $1}'); do git branch -D $branch; done search through all diffs git grep 'attr1' $(git rev-list --all) -- filename disable ssl certificate verification git -c http.sslVerify=false clone https://example.com/path/to/git git config --global http.sslVerify false use meld to display directory diff git difftool -t meld --dir-diff develop show current hooks directory git rev-parse --git-path hooks transfer commits via archive file git bundle create /tmp/a.bundle --all git bundle pull a.bundle https://git-scm.com/docs/git-bundle extract only the versioned files into an archive file git archive --output /tmp/a.bundle checkout from directories git init --bare git pull /home/my-checked-out-repository create a new empty branch without any history git checkout --orphan a ignore mode changes git config core.fileMode false reference identifiers HEAD: current commit checked out in your working directory HEAD@{<n>}: refers to the state of HEAD n changes ago HEAD^: refers to the parent of the current commit HEAD^^: equivalent to HEAD~2 HEAD~n: refers to the nth ancestor of the current commit branchname: refers to the latest commit on the specified branch commithash: refers to a specific commit identified by its sha-1 hash tagname: refers to the commit that a specific tag points to