Tutorial by Examples: branch

[alias] logp=log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short lg = log --graph --date-order --first-parent \ --pretty=format:'%C(auto)%h%Creset %C(auto)%d%Creset %s %C(green)(%ad) %C(bold cyan)<%an>%Creset' lgb = log --graph --date-order --branches --first-paren...
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...
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 ...
You can create a new branch and switch to it using git checkout -b AP-57 After you use git checkout to create a new branch, you will need to set that upstream origin to push to using git push --set-upstream origin AP-57 After that, you can use git push while you are on that branch.
The core idea behind the Feature Branch Workflow is that all feature development should take place in a dedicated branch instead of the master branch. This encapsulation makes it easy for multiple developers to work on a particular feature without disturbing the main codebase. It also means the mast...
It is also possible to create archives of other items than HEAD, such as branches, commits, tags, and directories. To create an archive of a local branch dev: git archive --output=archive-dev.zip --prefix=src-directory-name dev To create an archive of a remote branch origin/dev: git archive --...
git diff branch1..branch2
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...
To clone a specific branch of a repository, type --branch <branch name> before the repository url: git clone --branch <branch name> <url> [directory] To use the shorthand option for --branch, type -b. This command downloads entire repository and checks out <branch name>. ...
If while working you realize you're on wrong branch and you haven't created any commits yet, you can easily move your work to correct branch using stashing: git stash git checkout correct-branch git stash pop Remember git stash pop will apply the last stash and delete it from the stash list. T...
An existing working copy can be quickly transformed to reflect the contents of a different branch in the same repository. For example, you might have a working copy of the trunk and now need to work on a development branch. Instead of checking out a completely new working copy (which can waste a l...
Callbacks are often used to provide error handling. This is a form of control flow branching, where some instructions are executed only when an error occurs: const expected = true; function compare(actual, success, failure) { if (actual === expected) { success(); } else { failure...
You can quickly switch to the previous branch using git checkout -
If you are inside a folder of a git repository it might be nice to show the current branch you are on. In ~/.bashrc or /etc/bashrc add the following (git is required for this to work): function prompt_command { # Check if we are inside a git repository if git status > /dev/null 2>&a...
$ 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'...
$ git log @{upstream}.. # what was done locally and not yet published, current branch $ git show master@{upstream} # show upstream of branch 'master' The suffix @{upstream} appended to a branchname (short form <branchname>@{u}) refers to the branch that the branch specified by branc...
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...
Config a remote for my fork $ cd my_local_repo $ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git # Specify a new remote upstream repository that will be synced with the fork $ git remote -v # Verify the new upstream repository specified for my f...
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)

Page 2 of 4