Remove directory
rm -i -d folder-name
SEARCH
Search for a branch
$ git branch | grep 'ECOMIT'
View the change history of a file using Git versioning
$ gitk [filename]
CREATE
Clone an existing repository
$ git clone ssh://user@domain.com/repo.git
Create a new local repository
$ git init
LOCAL CHANGES
Changed files in your working directory
$ git status
Changes to tracked files
$ git diff
$ git diff > patchfile.patch
diff last commit
$ git diff HEAD^ HEAD
Add all current changes to the next commit
$ git add .
will let you also record the removals
$ git add --all
Add some changes in <file> to the next commit
$ git add -p <file>
Commit all local changes in tracked files
$ git commit -a
Commit previously staged changes
$ git commit -m 'message'
COMMIT HISTORY
Show all commits, starting with newest
$ git log
git log --pretty=oneline -3
Show changes over time for a specific file
$ git log -p <file>
Who changed what and when in <file>
$ git blame <file>
STASH
create stash
$ git stash
apply stash
$ git stash apply
$ git stash apply stash@{0}
remove a stash
$ git stash drop stash@{0}
remove all stashes
$ git stash clear
list stashes
$ git stash list
|
Git global setup
git config --global user.name "Pavel"
git config --global user.email "mp3-cdrs@ya.ru"
or edit .gitconfig
[user]
name = Username
email = user123@gmail.com
[core]
autocrlf = true
editor = 'C:/Users/user/Dropbox/apps/Sublime Text Build 3143 x64/sublime_text.exe' -w
[mergetool]
prompt = false
keepBackup = false
keepTemporaries = false
[merge]
tool = winmerge
[mergetool "winmerge"]
name = WinMerge
trustExitCode = true
cmd = "/c/Users/user/Dropbox/apps/WinMerge/WinMergeU.exe" -u -e -dl \"Local\" -dr \"Remote\" $LOCAL $REMOTE $MERGED
[diff]
tool = winmerge
[difftool "winmerge"]
name = WinMerge
trustExitCode = true
cmd = "/c/Users/user/Dropbox/apps/WinMerge/WinMergeU.exe" -u -e $LOCAL $REMOTE
[alias]
st = status
ci = commit
Diff with external tool
git difftool
Resolve conflict with external tool
git mergetool
Create a new repository
git clone https://gitlab.com/mp3-cdrs/spinner.git
cd spinner
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin https://gitlab.com/mp3-cdrs/spinner.git
git add .
git commit
git push -u origin master
Existing Git repository
cd existing_repo
git remote add origin https://gitlab.com/mp3-cdrs/spinner.git
git push -u origin --all
git push -u origin --tags
BRANCHES & TAGS
Delete a Git branch remotely
$ git push origin --delete branchName
List all existing branches
$ git branch -av
Switch HEAD branch
$ git checkout <branch>
Create a new branch based
on your current HEAD
$ git branch <new-branch>
New branch myFeature from the dev branch
$ git checkout -b myFeature dev
$ git branch -u origin/myFeature
$ git push -u origin bugfix/jira-issue
Delete a local branch
$ git branch -d <branch>
Mark the current commit with a tag
$ git tag <tag-name>
UPDATE & PUBLISH
List all currently configured remotes
$ git remote -v
Show information about a remote
$ git remote show <remote>
Add new remote repository, named <remote>
$ git remote add <shortname> <url>
Download all changes from <remote>,
but don‘t integrate into HEAD
$ git fetch <remote>
Download changes and directly
merge/integrate into HEAD
$ git pull <remote> <branch>
Publish local changes on a remote
$ git push <remote> <branch>
Delete a branch on the remote
$ git branch -dr <remote/branch>
Delete a remote branch
$ git push origin --delete <branchName>
|
MERGE & REBASE
Merge just one specific commit from another branch to your current branch.
$ git cherry-pick <commit>
Merge <branch> into your current HEAD
$ git merge <branch>
Merge <branch> into your current HEAD but do not actually make a commit
$ git merge <branch> --squash
Merge <branch> file into your current HEAD
$ git checkout <branch> <path to file>
Rebase your current HEAD onto <branch>
Don‘t rebase published commits!
$ git rebase <branch>
Abort a rebase
$ git rebase --abort
Continue a rebase after resolving conflicts
$ git rebase --continue
Use your configured merge tool to
solve conflicts
$ git mergetool
Use your editor to manually solve conflicts
and (after resolving) mark file as resolved
$ git add <resolved-file>
$ git rm <resolved-file>
before merging changes, you can also preview them by using
$ git diff <source_branch> <target_branch>
UNDO
# Reset the index and working tree to the desired tree
# Ensure you have no uncommitted changes that you want to keep
git reset --hard 56e05fced
# Move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}
git commit -m "Revert to 56e05fced"
discard changes in my working copy that are not in the index
$ git stash save --keep-index
$ git stash drop
Remove untracked files from the working tree and delete files or directories
$ git clean --force
$ git clean --f -d
Discard all local changes in your working directory
$ git reset --hard HEAD
Unstage all files
$ git reset
Discard local changes in a specific file
$ git checkout HEAD <file>
Revert a commit (by producing a new commit with contrary changes)
$ git revert <commit>
Revert a commit but do not make a commit
$ git revert --no-edit --no-commit <commit>
This will move your current HEAD to the given revision
$ git checkout HEAD~1
$ git checkout <sha>
Undo a merge. This will get you back to commit_sha
$ git reset --hard commit_sha
Change last commit message
git commit --amend
NPM PACKAGES
version of all installed packages
$ npm list
version of sintalled package
$ npm list (package)
install version of package
$ npm install (package)@(version)
show all versions of package
$ npm view (package) versions
DEBUG gulp task
DEBUG=* gulp [task]
|