btajfel / Gold-Team

Gold Team repository
1 stars 0 forks source link

How to Push/Pull Code on GitHub #73

Open tojaroslaw opened 5 years ago

tojaroslaw commented 5 years ago

If you want to make a change, make a new local branch. Make sure that your git bash is in the Gold-Team directory.

git checkout -b <branch_name>

This will create a new local branch with all of the code from the branch you are currently on. If you want to make changes to the code, remember to commit those changes using the command:

git commit -am '<commit_message>'

If you are ready to push those changes, but don't want to merge your code with master yet, push your code to a remote branch.

git push origin <branch_name>

This branch can now be checked out by the entire team. If you are ready to push to master, commit your changes to your local branch, then follow these steps:

  1. Commit your changes git commit -am '<commit_message>'

  2. Switch to the master branch git checkout master

  3. Pull from master git pull (if this doesn't work try this) git pull origin master

  4. Switch back to your local branch (some of these steps are redundant, but it reduces the likelihood of problems) git checkout <branch_name>

  5. Merge the two branches git merge master You may have to fix merge conflicts. You will see a list of files that need to be merged. When you are done fixing the merge conflicts, commit your work again: git commit -am '<commit_message>' If there are no conflicts, then you do not need to commit again.

  6. Switch back to master git checkout master

  7. Merge from your local branch git merge <branch_name>

  8. Push the changes git push or git push origin master

Try not to make changes directly in the master branch. Instead try to make separate branches for changes that you are making. Only push working commits to master.

tojaroslaw commented 5 years ago

As an added bonus, if you put 'resolves #<issue_number>' or 'fixes #<issue_number' in the commit message, it will automatically close the issue when you push that commit to master

tojaroslaw commented 5 years ago

Steps 6 and 7 are not strictly necessary, from inside your local branch, you can just run git push origin master once you've fixed the merge conflicts and committed the changes. Just remember to pull in the master branch next time you check it out to see that your changes were pushed. Steps 6 and 7 simply exist to reduce confusion later on.