Git

From IML Wiki
Jump to: navigation, search

git --help - show help
git --version - show git version
git init - initialize new folder with git
git status - show git status
git log - show all history of commits
git add filename - include untracked file to git
git add . - include all untracked files to git
git rm --cached filename - remove filename file from git
git commit -m "commit message" - commit
git config --global init.defaultBranch main – rename master branch to main
git branch - show current git branch
git branch branchname - create new branchname branch
git branch branchname -D or git branch -D branchname - delete branchname branch
git branch -m newbranchname - rename current branch
git checkout branchname - switsh to branchname branch
git checkout -b branchname - create new branchname branch and switch to it
git merge branchname - merge current branch with branchname branch

git config --global user.name - show current username
git config --global user.name "NewUsername" - define new "NewUsername" username

git config --global user.email - show current email
git config --global user.email "Newemail" - define new "Newemail" email

git config -l - show current username and email

git remote add origin https://example.com/git-example.git - set up remote repository with origin alias
git remote remove origin - remove setuped before origin remote alias
git push -u origin branchname - push the branchname branch to the origin remote alias
git push - push commits to the default origin
git pull - get new commits from the default remote alias

git checkout -- . - cancel all non staged files changes
git reset . & git checkout -- . - cancel all staged files changes
git reset --hard HEAD^ или git reset --hard <lastStableCommitHash> - cancel last commit
git reset --hard <commitHash> & git push --force - cancel last commit from git and gitHub

git clean -f -d - remove untracked files and directories.

git clone https://example.com/git-example.git - clone github repository (default branch) to current folder
git clone -b branchname https://example.com/git-example.git - clone github repository (from the branchname branch) to current folder

Octotree - GitHub code tree - chrome plugin for github