Tutorial by Examples: branches

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...
If a remote branch has been deleted, your local repository has to be told to prune the reference to it. To prune deleted branches from a specific remote: git fetch [remote-name] --prune To prune deleted branches from all remotes: git fetch --all --prune
Show the changes between the tip of new and the tip of original: git diff original new # equivalent to original..new Show all changes on new since it branched from original: git diff original...new # equivalent to $(git merge-base original new)..new Using only one parameter such as ...
git diff branch1..branch2
$ git log master # specify branch $ git show v1.0 # specify tag $ git show HEAD # specify current branch $ git show origin # specify default remote-tracking branch for remote 'origin' You can specify revision using a symbolic ref name, which includes branches (for example 'master'...
In some cases the behavior of a command depends on whether it is given branch name, tag name, or an arbitrary revision. You can use "de-referencing" syntax if you need the latter. A suffix ^ followed by an object type name (tag, commit, tree, blob) enclosed in brace pair (for example v0.9...
git log master..foo will show the commits that are on foo and not on master. Helpful for seeing what commits you've added since branching!
bookmarks, bookmark: create a new bookmark or list existing bookmarks branch: set or show the current branch name tag: add one or more tags for the current or given revision update, up, checkout, co: update working directory (or switch revisions)
d = Dates.dayofweek(now()) if d == 7 println("It is Sunday!") elseif d == 6 println("It is Saturday!") elseif d == 5 println("Almost the weekend!") else println("Not the weekend yet...") end Any number of elseif branches may be used...
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>
Sometimes you might have branches lying around that have already had their changes merged into master. This finds all branches that are not master that have no unique commits as compared to master. This is very useful for finding branches that were not deleted after the PR was merged into master. ...
One of most common use cases of Gitflow Initialize repo and define branches $ git flow init # if you use default setup, you'll define six types of branches: # # main branches (lives forever) # # 1. master: for production releases # 2. develop: for "next ...
To remote tracking between local and deleted remote branches use git fetch -p you can then use git branch -vv to see which branches are no longer being tracked. Branches that are no longer being tracked will be in the form below, containing 'gone' branch 12345e6 [origin/bran...

Page 1 of 1