configure user name
git config --global user.name “[name]”
configure user email
git config --global user.email “[email address]”
configure initial default branch
git config --global init.defaultBranch [branch]
initialize repository in current folder
git init
initialize repository in folder
git init [repository folder name]
clone repository
git clone [url] [optional name]
view remotes
git remote -v
add remote
git remote add [variable name] [Remote Server Link]
remove remote
git remote rm [variable name]
rename remote
git remote rename [old variable name] [new variable name]
changes an existing remote repository URL
git remote set-url [variable name] [Remote Server Link]
add file or folder to stage
git add [file or folder/]
add all files and folders to stage
git add .
commit staged files
git commit -m “[commit message]”
add and commit files and folder with previous commit
git commit -am “[commit message]”
replace previus commit
git commit --amend -m “[new commit message]”
switch to commit/branch/tag
git checkout [commit/branch/tag]
create and switch to branch
git checkout -b [branch name]
restore projecto to previous commit
git checkout .
restore file or folder to previous commit
git restore [file or folder/]
restore projecto to previous commit
git restore .
revert changes of previous commit and create a new commit
git revert HEAD
unstage file or folder
git reset [file or folder/]
unstage all changes
git reset .
reset to commit but changes are maintained
git reset HEAD~[number of commits behind]
reset to commit but changes are maintained
git reset [commitID]
reset all project to commit
git reset --hard [commitID]
list tags
git tag -l *[optional filter]*
create tag in current commit
git tag [tag name]
create annotated tag in current commit
git tag -a [tag name] -m "[tag message]"
delete tag
git tag -d [tag name]
fetch and merge changes from remote to local repository
git pull [variable name] [branch]
pull unrelated histories
git pull [variable name] [branch] --allow-unrelated-histories
add remote-tracking reference
git push -u [variable name] [branch]
push branch to remote
git push [variable name] [branch]
push all branch to remote
git push --all [variable name]
delete remote branch
git push [variable name] :[branch name]
git push [variable name] -d [branch name]
push tag to remote
git push origin [variable name] [tag name]
force push
git push -f
create branch
git branch [branch name]
delete local branch
git branch -d [branch name]
delete remote-tracking branch
git branch -d -r [variable name/branch]
merge changes from branch to current branch
git merge [branch name]
merge changes to branch from branch
git merge [branch name] [branch name]
rebase to branch
git rebase [branch]
rebase from parent branch to child branch
git rebase [parent branch] [child branch]
interactive rebase
git rebase -i HEAD~[number of commits behind]
stash uncommited changes with a message
git stash save "[stash message]"
re-apply stash
git stash pop [stashID]
view stash list
git stash list
delete stash
git stash drop [stashID]
add an existing commit to the current branch
git cherry-pick [commitID]