Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

gitBranchAndMerge

Shaan Menon edited this page Oct 23, 2015 · 6 revisions

#Git Branch and Git Merge


Go Back to Home Page

Git Basics


git branch


$ git branch master branchName

This command creates a local branch for you not to directly effect the repository. This is especially usefull when i group projects where someone or a group of people want to review the changes you make before going live. You are able to play around as much as you want in your own branch and then allopw someone to review it before merging it with the current working branch for the group. There are many flags that can go with this command. Here is a list and explaination of the key ones we think that you should learn.

$ git branch -d branchName

or

$ git branch --delete branchName

This deletes the branch specified. This is done generally after that branch has been merged with the repository, or it is deemed that what was being worked on in the branch is not needed.

$ git branch -m old new

or

$ git branch --move old new

This allows you to change the name of a branch to something else. You would use this in the case that the branch is now for doing something else and you want the name to reflect what it does. generally branch names should reflect what the branch is for.

$ git branch -f branchName

or

$ git branch --force branchName

This resets your branch to the way it was when you created it. use this only if you nade a fatal mistake that can only be corrected that way or you are no longer working on what it was originally for but you will still use the branch for something else. You would then generally change the name of the branch too.

$ git branch --edit-description branchName

This is usefull for if you want to explain in more detail what the branch is for and you think the name wont just sufice. It allows others who might look at the branch later the ability to better understand what is going on with your branch so they can make merge descisions better.

More Info on git branch


git merge


$ git merge branchName

This is used to combine a branch with another branch that is usually the master or closer to the master than the one we specify. This command brings together two working trees of commits. Here are flags that are used with it.

$ git merge --squash branchName

This is used when we want to stage a merge but not actually do the final steps of commiting and pushing together. This is usefull for when we want others to review the merge before we let it go through.

$ git merge --no-commit branchName

This is like squash but for the user to be able to review the changes before making the commit. Use this if you want to make sure that the merge happened corectly before actually completing it.

$ git merge -m "message"

This is for writing a message with your merge so when someone looks at the commit log they see this and understand what the merge was done for without having to look back at the entire merge itself.

$ git merge --abort

Incase a problem has occured during the merge and you need to revert to a pre merge state this is the command that you would use. This attempts to bring you back to when you had both branches seprate without the merge. Sometimes we cant resolve a merge error so we have to do this and find a way around it.

More Info on git merge


Clone this wiki locally