© We Can Code IT, LLC
master
is the default branch for any Git repository when it is created.Merging takes the changes and deviations you have been working on separate from the project and merges them back into another branch (usually master
).
Advantages:
What happens when two people on a team are working with the same section of code? Conflicts can arise. How do you resolve these conflicts?
master
.master
should be reserved for working, clean, and tested code while all of the members of the team are doing their work in their separate branches.master
, you should go to GitHub and create a Pull Request for your branch.master
into your branch regularly..gitignore
file goes a long way towards preventing merge conflicts!! ALWAYS include a .gitignore
!Remember…
.gitignore
file in your project before initializing your Git repository.Whenever you create a branch, it's taking the most recent code and making a copy for that branch. The branch starts from wherever you currently are when you create your branch.
This command creates the branch, but keeps you in your current branch:
git branch branchName
, where 'branchName' is replaced by the name of your new branch.This command creates the branch and then switches you over to the new branch you've created:
git checkout -b branchName
, where "branchName" is replaced by whatever you are naming your branch.testBranch
.git push origin master
git push origin branchName
where "branchName" is replaced by whatever your branch's name is.git checkout
is the code we use to switch from one branch to another. Example: git checkout master
from testBranch
git push origin --all
will push all of your branches to Github. Use sparingly because you don't want to be pushing non-functional branches and you don't want all of the members of your team to have to delete the bad branches.Merging is when we bring the changes back in to another branch (usually master
)
git checkout master
and git merge testBranch
merges the testBranch
into master
Here are 2 examples of merge commands:
git merge -m "Merge Message" branchName
where "Merge Message" is replaced by the message you want to include and branchName
is the branch you are merging ingit merge branchName
where branchName
is the branch you are merging inWe will be using feature branches to build out all of our content for future team projects and the final project. All feature branches will be verified and merged to master via Pull Requests (PR).
Do not code on master on your local machine, but if you find yourself in this position we can fix it:
git stash
will take all of your changes on master and remember themgit checkout -b new-branch
then git stash apply
will take these changes you had on master and place them on your new branchDo not add/commit/push to the master branch
Make a feature branch for every "feature" you plan on adding into your application Since we work in iterations, these should be todos from your trello cards for a particular sprint
Name your feature branch to match the feature you are building
git checkout -b account-and-bank-build
may be a branch that a dev creates to test and build these entities outYou can add
/ commit
/ push
to this branch as much as you would like
When ready, submit a Pull Request on GitHub
A teammate will verify the pull request (PR) and merge the changes into master on GitHub
Entire team can do a git pull
to pull these changes into master
Remember, git checkout master
allows you to leave a feature branch and go back to master
bash will warn you to add and commit your changes before it will let you leave a branch!
git checkout branch-name
allows you to move from master or one branch to another…again, bash will make sure all changes are stored before letting you out of a branch
Keep it very very simple. No more and no less than what has been described. There is no need to do any rebasing or to get crazy with the endless commands that googling bash issues could lead you to
COMMUNICATE COMMUNICATE COMMUNICATE!
Work on separate parts of the app…definitely ensure you are in different files to avoid major merge conflicts
Be sure to avoid any manual uploads to Git Hub, these most likely will unintentionally go to master
For this exercise you will need at least two people, Person A and Person B. Changes should not be made in master directly, but rather, each person should make changes in a branch and merge them into master.
Have Person A create a new project, create a Git repository, and add a .gitignore file. Next, they should perform an initial commit and push the code to a new GitHub repository.
Person A should go into the Git repository's "Settings" and add Person B as a collaborator under "Collaborators & teams".
Person B should accept the invite via email (or via the sharable link from Person A).
git clone [url copied from the repository]
git clone
command wherever you would like the folder to be created on your computer. For example, if you run the git clone
command in the ~/source/repos/Projects
directory, the project folder would be created at ~/source/repos/Projects/[ProjectName]
cd
command. For example, if you ran your git clone
command in the ~/source/repos/Projects
and your project was called GitBranchTest
, you would then need to run cd GitBranchTest
to navigate to the project directory.~/source/repos/Projects/GitBranchTest (master)
git checkout -b [newBranchName]
Person B should make a few small changes, and commit those changes locally.git push origin [newBranchName]
master
. First, they should checkout master with git checkout master
. Then, to merge their changes into master, they should run git merge -m "[merge message]" [newBranchName]
git pull
to make sure you have the most recent code. Then you can update origin by running git push origin master
git checkout master
. To get the most recent changes, they can run git pull
. If there are more than 2 people working on the project, everyone can run this step now to ensure all are up-to-date.You can repeat these steps, alternating who is creating a branch and adding changes until you feel comfortable with the process.
You can also reuse any of the already created branches. You should first checkout the branch, make your changes, commit, and follow the same steps from there.
You can use the "Network" graph under the "Insights" tab on the GitHub repository to help verify the state and relationship of the different branches.