Git is a distributed version control system that differs in some characteristics from typical version control systems. Both branching and merging two or more branches are integral parts of working with Git and are built into the Git tools. Git contains programs that make it easy to visualize the non-linear history of a project and navigate that story. Branches in Git are implemented very effectively (unlike other SCMs) – a branch represents only a reference, reff or short, a text file with a commit ID, which is stored in a repository in the directory (e.g. for the master branch) and refers to a specific commit. The branch structure can be reconstructed using its parental commits. Through these properties, very large and efficient development structures can also be realized, as with Git itself or the Linux kernel, in which each feature and each developer has a branch or its repository, from which the project manager (“maintainer”) can then transfer commits via a merge or cherry-pick (use of individual commits) into the main branch of the project (master).
Each user owns a local copy of the entire repository, including the history. This allows most actions to be performed locally and without network access. No distinction is made between local development branches and development branches of remote repositories. Although there is no technical difference between different repositories (except that between normal and bare repositories on servers where there is no working tree, i.e. the real files), the copy referenced from a project homepage is often considered the official repository to which the developers’ revisions are transferred. There are special remote-tracking branches. These are references (see Non-Linear Development) that point to the state of another repository.
# Create and checkout new branch based on the current branch
git checkout -b
---
# Undo all local pending changes
git reset –hard HEAD
# Erase the last 3 commits
git reset –hard HEAD~3
# Undo a single file change
git checkout —
# Push the new branch to the server
git push origin
# Delete remote branch
git push origin –delete
# List all local and remote branches
git branch -a
# Remove remotely deleted branches (this will not delete local branches, but delete only the copies of remotes)
git remote prune origin
# Pull remote master branch and merge it into the current branch
git pull origin master
# Undo the last commit but keep changes unstaged
git reset HEAD~1
# Rename current branch
git branch -m
# Save changes temporarily – branch independent
git stash
# List temporary saves
git stash list
# Apply temporarily saved changes
git stash apply
# Delete temporary saves
git stash drop
# Delete untracked files and directories (-n to just test)
git clean -fd
# Resolve conflict by accepting their changes
git checkout –theirs
# Interactive stage / unstage
git add -i
# Compare branch to another branch
git diff
#display all changes with additions/deletions between two branches
git diff –stat master..
#display the active branches
git branch -va –sort=committerdate