Changes

Line 157: Line 157:     
When you create a branch in your project, you're creating an environment where you can try out new ideas. Changes you make on a branch don't affect the master `branch`, so you're free to experiment and commit changes, safe in the knowledge that your branch won't be merged until it's ready to be reviewed by someone you're collaborating with.
 
When you create a branch in your project, you're creating an environment where you can try out new ideas. Changes you make on a branch don't affect the master `branch`, so you're free to experiment and commit changes, safe in the knowledge that your branch won't be merged until it's ready to be reviewed by someone you're collaborating with.
 +
 +
It is highly recommended that all work you do, should be done in a new branch so that even in case your changes break the code(which happens quite frequently for beginners), you can always easily just remove that branch and start again, and also it helps you to work on two different features simultaneously as you can do that in separate branches.
 +
 +
==== Using GitHub Website ====
 +
 +
You can create a new branch in a repository's branch selector menu. Just start typing the name of your branch; if it doesn't exist, GitHub will offer to create it for you:
 +
 +
Likewise, if you go to the Branches page on your repository, you have the option of deleting a branch, provided you have appropriate access to the repository, and that there isn’t an open pull request that depends on it:
 +
 +
==== Using the Terminal ====
 +
 +
The `git branch` command lets you create, list, rename, and delete branches. It doesn’t let you switch between branches or put a forked history back together again. For this reason, git branch is tightly integrated with the `git checkout` `and git merge` commands.
 +
 +
List all of the branches in your repository:
 +
git branch
 +
 +
Create a new branch called <branch>. This does not check out the new branch:
 +
git branch <branch>
 +
 +
Delete the specified branch. This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes:
 +
git branch -d <branch>
 +
 +
Force delete the specified branch, even if it has unmerged changes. This is the command to use if you want to permanently throw away all of the commits associated with a particular line of development:
 +
git branch -D <branch>
 +
 +
Rename the current branch to <branch>:
 +
git branch -m <branch>
 +
 +
Check out the specified branch, which should have already been created with git branch. This makes <existing-branch> the current branch, and updates the working directory to match:
 +
git checkout <existing-branch>
 +
 +
Create and check out <new-branch>. The -b option is a convenience flag that tells Git to run git branch <new-branch> before running git checkout <new-branch>:
 +
git checkout -b <new-branch>
 +
 +
Same as the above invocation, but base the new branch off of <existing-branch> instead of the current branch:
 +
git checkout -b <new-branch> <existing-branch>
 +
 +
Merge the specified branch into the current branch. Git will determine the merge algorithm automatically:
 +
git merge <branch>
 +
 +
Merge the specified branch into the current branch, but always generate a merge commit (even if it was a fast-forward merge). This is useful for documenting all merges that occur in your repository:
 +
git merge --no-ff <branch>
    
==== Tip ====
 
==== Tip ====
Line 162: Line 204:  
There's only one rule: anything in the master branch is always deployable.
 
There's only one rule: anything in the master branch is always deployable.
   −
Because of this, it's extremely important that your new branch is created off of master when working on a feature or a fix. Your branch name should be descriptive  
+
Because of this, it's extremely important that your new branch is created off of master when working on a feature or a fix. Your branch name should be descriptive
 +
 
 +
For detailed explanation, look at the [https://www.atlassian.com/git/tutorials/using-branches/git-merge '''atlassian git tutorial''']
    
=== Commits ===
 
=== Commits ===
135

edits