Tutorial by Examples: branch

git diff This will show the unstaged changes on the current branch from the commit before it. It will only show changes relative to the index, meaning it shows what you could add to the next commit, but haven't. To add (stage) these changes, you can use git add. If a file is staged, but was modi...
git merge incomingBranch This merges the branch incomingBranch into the branch you are currently in. For example, if you are currently in master, then incomingBranch will be merged into master. Merging can create conflicts in some cases. If this happens, you will see the message Automatic merge ...
Rebasing reapplies a series of commits on top of another commit. To rebase a branch, checkout the branch and then rebase it on top of another branch. git checkout topic git rebase master # rebase current branch onto master branch This would cause: A---B---C topic / D---E---F---G...
A submodule is always checked out at a specific commit SHA1 (the "gitlink", special entry in the index of the parent repo) But one can request to update that submodule to the latest commit of a branch of the submodule remote repo. Rather than going in each submodule, doing a git checkout...
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...
To delete a remote branch in Git: git push [remote-name] --delete [branch-name] or git push [remote-name] :[branch-name]
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
Branching in Subversion is very simple. In the simplest form, creating a new branch requires you to run the command against the remote repository's URLs. For example, let's create a new branch out of the mainline trunk: svn copy https://svn.example.com/svn/MyRepo/MyProject/trunk https://svn.example...
When you interact with the remote central repository using your private local workspace -- the working copy -- you can use repository-relative URL instead of direct URL to URL copy to create a new branch: svn copy "^/MyProject/trunk" "^/MyProject/branches/MyNewBranch" -m "C...
git cherry-pick <commit-hash> will apply the changes made in an existing commit to another branch, while recording a new commit. Essentially, you can copy commits from branch to branch. Given the following tree (Source) dd2e86 - 946992 - 9143a9 - a6fd86 - 5a6057 [master] \ ...
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...
To recover a deleted branch you need to find the commit which was the head of your deleted branch by running git reflog You can then recreate the branch by running git checkout -b <branch-name> <sha1-of-commit> You will not be able to recover deleted branches if git's garbage col...
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 cherry-pick <commit-A>..<commit-B> will place every commit after A and up to and including B on top of the currently checked-out branch. git cherry-pick <commit-A>^..<commit-B> will place commit A and every commit up to and including B on top of the currently checked-out...
General syntax git push <remotename> <object>:<remotebranchname> Example git push origin master:wip-yourname Will push your master branch to the wip-yourname branch of origin (most of the time, the repository you cloned from). Delete remote branch Deleting the remote br...
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

Page 1 of 4