Git
Git Commands
git config --global user.name "Your Name" - Set the name that will be attached to your commits and tags.
git config --global user.email "" - Set the e-mail address that will be attached to your commits
and tags.
git config --global color.ui auto - Enable some colorization of Git output.
git init [project name]
git clone [project url]
git status
git diff [file]
git diff --staged [file]
git checkout -- [file]
git add [file]
git commit [-m "message here"]
git rm [file] - Remove file from working directory and add deletion to staging area.
git branch [-a] List all local branches in repository. With -a: show all branches (with remote).
git branch [name] Create new branch, referencing the current HEAD.
git checkout [-b] [name] Switch working directory to the specified branch. With -b: Git will create the specified
branch if it does not exist.
git merge [from name] Join specified [from name] branch into your current branch (the one you are on currenlty).
git branch -d [name] Remove selected branch, if it is already merged into any other. -D instead of -d forces
deletion
git log [-n count] List commit history of current branch. -n count limits list to last n commits.
git log --oneline --graph --decorate An overview with references labels and history graph. One commit per line.
git log ref.. List commits that are present on current branch and not merged into ref. A ref can be e.g. a branch
name or a tag name.
git log ..ref List commit, that are present on ref and not merged into current branch.
git reflog List operations (like checkouts, commits etc.) made on local repository
git fetch [remote] Fetch changes from the remote, but not update tracking branches.
git fetch --prune [remote] Remove remote refs, that were removed from the remote repository.
git pull [remote] Fetch changes from the remote and merge current branch with its upstream.
git push [--tags] [remote] Push local changes to the remote. Use --tags to push tags.
git reset [file] - Get file back from staging area to working directory
git reset --soft
git reset --mixed
git reset --hard
git revert HEAD - Undo the commit and create a new commit
git branch –d [head] - Delete the Current Branch
git branch -d <branch> - (Only works if it is merged with another branch)
git branch -D <branch> - (Forcing the delete)
git reflog --no-abbrev - contains all log information of the steps you have done
git checkout [sha]
git checkout -b [branchname] <sha>
, git branch --merged master lists branches merged into master
git branch --merged lists branches merged into HEAD (i.e. tip of current branch)
git branch --no-merged lists branches that have not been merged
git stash
git stash apply
git stash pop
git stash drop
CVCS vs DVCS ?
CVCS DVCS
One Central repository which is a server Every user has a complete repository which is called as
local repository
Every User who needs to access must be connected to We can go offline in DVCS but Network is needed to
the Network share repositories with others
SVN Git, Mercurial, Bazaar
Which Branching Strategy used in your Project ?
Git Commands
git config --global user.name "Your Name" - Set the name that will be attached to your commits and tags.
git config --global user.email "" - Set the e-mail address that will be attached to your commits
and tags.
git config --global color.ui auto - Enable some colorization of Git output.
git init [project name]
git clone [project url]
git status
git diff [file]
git diff --staged [file]
git checkout -- [file]
git add [file]
git commit [-m "message here"]
git rm [file] - Remove file from working directory and add deletion to staging area.
git branch [-a] List all local branches in repository. With -a: show all branches (with remote).
git branch [name] Create new branch, referencing the current HEAD.
git checkout [-b] [name] Switch working directory to the specified branch. With -b: Git will create the specified
branch if it does not exist.
git merge [from name] Join specified [from name] branch into your current branch (the one you are on currenlty).
git branch -d [name] Remove selected branch, if it is already merged into any other. -D instead of -d forces
deletion
git log [-n count] List commit history of current branch. -n count limits list to last n commits.
git log --oneline --graph --decorate An overview with references labels and history graph. One commit per line.
git log ref.. List commits that are present on current branch and not merged into ref. A ref can be e.g. a branch
name or a tag name.
git log ..ref List commit, that are present on ref and not merged into current branch.
git reflog List operations (like checkouts, commits etc.) made on local repository
git fetch [remote] Fetch changes from the remote, but not update tracking branches.
git fetch --prune [remote] Remove remote refs, that were removed from the remote repository.
git pull [remote] Fetch changes from the remote and merge current branch with its upstream.
git push [--tags] [remote] Push local changes to the remote. Use --tags to push tags.
git reset [file] - Get file back from staging area to working directory
git reset --soft
git reset --mixed
git reset --hard
git revert HEAD - Undo the commit and create a new commit
git branch –d [head] - Delete the Current Branch
git branch -d <branch> - (Only works if it is merged with another branch)
git branch -D <branch> - (Forcing the delete)
git reflog --no-abbrev - contains all log information of the steps you have done
git checkout [sha]
git checkout -b [branchname] <sha>
, git branch --merged master lists branches merged into master
git branch --merged lists branches merged into HEAD (i.e. tip of current branch)
git branch --no-merged lists branches that have not been merged
git stash
git stash apply
git stash pop
git stash drop
CVCS vs DVCS ?
CVCS DVCS
One Central repository which is a server Every user has a complete repository which is called as
local repository
Every User who needs to access must be connected to We can go offline in DVCS but Network is needed to
the Network share repositories with others
SVN Git, Mercurial, Bazaar
Which Branching Strategy used in your Project ?