-
show config value
git config --global user.name -
edit all config values
nano ~/.gitconfig
-
generate keys - see generating a new ssh key
ssh-keygen -t ed25519 -C "your_email@example.com" -
copy pub key to clipboard
cat ~/.ssh/id_ed25519.pub -
or
cat ~/.ssh/id_rsa.pub -
start SSH agent (Linux)
eval "$(ssh-agent -s)" -
add key to local ssh agent
ssh-add ~/.ssh/id_ed25519 -
add key to GitHub
See Adding a new SSH key to your github account.
-
activate access to GitHub via ssh
ssh -T git@github.com (select "yes")
-
clone repo via ssh (if configured)
git clone git@github.com:jquery/jquery.git -
clone repo via HTTPs
git clone https://github.com/jquery/jquery.git -
make new dir and init
git init foo -
init repo in current dir
git init
-
add single file to staging
git add about.html -
add all files to staging
git add .
-
list files with executable/read/write flags
git ls-files --stage -
activate executable flag (from 644 to 755)
git update-index --chmod=+x <file-name> ex. git update-index --chmod=+x foo.sh
-
interactive commit
git commit --interactive -
commit old but not staged
git commit -a -
commit with editor for message
git commit -
commit with message from CLI
git commit -m "Commit message" -
add and commit
git commit -am "Add more lives"
-
show log of changes
git log -
show log (compact format)
git log --oneline -
or
git log --pretty --oneline -
show modified files in log
git log --stat -
show log with single comment and modified files
git log --oneline --stat -
show changes (diff) for entries in log
git log --patch -
show only 3 last log entries
git log -3 -
filter entries basing on dates
git log --since="2018-08-15" git log --until="2018-08-15" git log --since="2 days ago" -
filter entries basing on commit message
git log --grep="paddle" -
graph of changes for branches
git log --graph
-
show introduced changes except staged
git diff -
show introduced changes in staging area
git diff --staged -
show differences between current and past version of file
git diff e2fdef3ba engine.js -
show differences between 2 versions of file
git diff e2fdef3ba b732187 engine.js
-
show list of modified files
git status
-
retrieve selected revision from repo to local copy
git checkout f3121788 -
return to current revision
git checkout master -
verify which revision is current
cat .git/HEAD
-
show available branches
git branch -
or
ls .git/refs/heads -
list branches with latest changes
git branch -vv -
create new branch
git branch new_branch -
switch to branch
git checkout new_branch -
return to "trunk"
git checkout master -
delete branch
git branch -d new_branch -
create branch and switch to it
git checkout -b new_branch -
merge changes from branch to master
git checkout master git merge hotfix-001 -
correct merge conflict
git mergetool variables.js -
apply branch changes to new base
git checkout new_feature git rebase master -
cherry pick - merge single commit
git cherry-pick e6f4c858af -
rebase branch in interactive mode
git rebase -i new_long_feature -
show branch history
git show --summary >release.log
-
add to last commit and modify it's description
git commit --amend -
remove file from staging area
git reset draw.js -
return to clean working dir (revert local changes)
git checkout . -
revert local changes in single file
git checkout engine.js -
revert last commit
git reset HEAD~ -
revert commit in history
git reset HEAD~1 -
revert commit, keep changes in staging
git reset --soft HEAD~ -
revert commit, do not keep changes
git reset --hard HEAD~ -
list base changes
git reflog -
go back to base version from reflog
git reset --hard HEAD@{3} -
revert last commit, keep history
git revert HEAD -
list changes in selected revision
git show HEAD~1 -
compare current version with selected revision (verify revert)
git diff HEAD~2 -
show changes in last commit
git show HEAD -
compare branches in log
git log master..new_long_feature -
or
git log master..origin/master
-
check address of remote repo
git remote -v -
or
git config --get remote.origin.url -
more verbose
git remote show origin -
add remote repo to existing working dir
git remote add origin https://github.com/Biegal/arkanoid-1.git -
add nth remote repo to existing working dir
git remote add nth-node https://github.com/Biegal/arkanoid-2.git -
rename remote node
git remote rename nth-node secondary_node -
remove link to remote node
git remote rm secondary_node
-
note: push requires remote repo connected, it can be done via
git remote add origin {remote-path} -
first push
git push --set-upstream origin master -
push local changes to remote repo
git push origin master:master -
subsequent push
git push -
push from branch
git checkout new_long_feature git push --set-upstream origin new_long_feature:add_scoreboard
e.g.
git push --set-upstream origin local-branch-name:remote-branch-name
next:
git push secondary
git push origin my_local:my_remote
-
fetch latest changes
git fetch -
fetch from selected remote host
git fetch origin -
show log of remote repo
git log origin/master -
merge latest changes from remote with local repo
git merge origin/master -
fetch & merge changes
git pull -
fetch, merge & rebase changes
git pull --rebase
-
list tags
git tag -
show changes in tags
git show v.0.3 -
create tag
git tag v.0.4 2ffb638 -
create tag with author, date and description
git tag -a v.0.6 -
list tags with filtering
git tag -l 'v.0.2*' -
delete tag
git tag -d v.0.5 -
push single tag to remote repo
git push origin v.0.6 -
push all tags
git push --tags
-
put changes to stash & revert local changes
git stash -
list changes in stash
git stash list -
put changes to stash with change description
git stash save refactoring_of_mouse_move_handler -
show changed files in selected stash
git stash show stash@{0} -
e.g.
git stash show <stash-id> -
show changed files with diff in selected stash
git stash show -p stash@{0} -
apply changes from selected stash
git stash apply stash@{1} -
apply most recent stash & delete it (requires clean file)
git stash pop -
delete (drop) selected stash
git stash drop stash@{1} -
delete all stashes
git stash clear
-
edit local excludes (not saved to repo)
nano .git/info/exclude -
website for generation of gitignore files
-
define alias "co"
git config --global alias.co checkout -
use alias "co"
git co -
define alias "s"
git config --global alias.s status -
use alias "s"
git s -
to list defined aliases check config section "alias"
nano ~/.gitconfig -
define alias to filter log with grep ('!' starts a script)
git config --global alias.flog '!git log --oneline| grep' -
use grep alias
git flog paddle
-
create patch file for selected commit (and only this commit: -1)
git format-patch -1 6cec3f5 -
create patch for differences between current and selected branch, save output to given "patches" dir, saves changes that are in current branch but not in given branch
git format-patch a_big_feature_branch -o patches -
apply changes (& commit) from patch to selected branches
git checkout a_big_feature_branch git am patches/0001-a-nice-change.patch -
or just check for conflicts
git apply --check ../001-a-nice-change.patch -
or apply without commit
git apply ../001-a-nice-change.patch
-
how to install
https://github.com/nvie/gitflow/wiki/Linux -
how to use git flow extensions:
https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow https://danielkummer.github.io/git-flow-cheatsheet/
-
prune local branches
git remote prune origin -
clean work dir
git checkout -- . git clean -f -d
- O k.., Git!?! - commands for rescue