Tutorial by Examples

Git provides multiple commands for listing branches. All commands use the function of git branch, which will provide a list of a certain branches, depending on which options are put on the command line. Git will if possible, indicate the currently selected branch with a star next to it. GoalCommand...
To create a new branch, while staying on the current branch, use: git branch <name> Generally, the branch name must not contain spaces and is subject to other specifications listed here. To switch to an existing branch : git checkout <name> To create a new branch and switch to it...
$ git branch -d dev Deletes the branch named dev if its changes are merged with another branch and will not be lost. If the dev branch does contain changes that have not yet been merged that would be lost, git branch -d will fail: $ git branch -d dev error: The branch 'dev' is not fully merged...
There are three ways of creating a new branch feature which tracks the remote branch origin/feature: git checkout --track -b feature origin/feature, git checkout -t origin/feature, git checkout feature - assuming that there is no local feature branch and there is only one remote with the featur...
Rename the branch you have checked out: git branch -m new_branch_name Rename another branch: git branch -m branch_you_want_to_rename new_branch_name
The checked out file will overwrite not yet commited changes you did in this file. This command will check out the file file.example (which is located in the directory path/to/) and overwrite any changes you might have made to this file. git checkout some-branch path/to/file some-branch can be ...
To delete a branch on the origin remote repository, you can use for Git version 1.5.0 and newer git push origin :<branchName> and as of Git version 1.7.0, you can delete a remote branch using git push origin --delete <branchName> To delete a local remote-tracking branch: git bra...
git checkout --orphan new-orphan-branch The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits. source
Use to push commits made on your local branch to a remote repository. The git push command takes two arguments: A remote name, for example, origin A branch name, for example, master For example: git push <REMOTENAME> <BRANCHNAME> As an example, you usually run git push orig...
A branch is just a pointer to a commit, so you can freely move it around. To make it so that the branch is referring to the commit aabbcc, issue the command git reset --hard aabbcc Please note that this will overwrite your branch's current commit, and as so, its entire history. You might loose s...
You can quickly switch to the previous branch using git checkout -
To list local branches that contain a specific commit or tag git branch --contains <commit> To list local and remote branches that contain a specific commit or tag git branch -a --contains <commit>

Page 1 of 1