-
Notifications
You must be signed in to change notification settings - Fork 5
Push, Pull, Branch and Pull Request
Huy Anh Nguyen edited this page Dec 28, 2018
·
3 revisions
This is a guide to help you with contributing to this project.
- When you change something and want the remote repository (the project files stored online in github) to be updated to your changes, you will need to push the changes to the remote repository. That is called pushing.
- When someone else has changed something to the repository, you will need to get those changes to your local repository. Getting those changes to your local project folder is called pulling.
- When multiple people work on the same project, sometimes they can all change a file, and there is no way to update all of their changes without having conflicts. To do so, we can create smaller workspaces (branches) for each person working on the project, so that they can push their changes without messing with the main repository codes (master branch). One someone has finished with the changes, they can notify a manager to merge their changes with the master branch. They can do so using a pull request.
TL;DR: push is updating your local changes to online, pull is getting changes from online to local, and pull request is to signify the manager that you have finished a change and want to merge to main code.
For all of these below, you need to go to the local repository folder in the terminal/command prompt using 'cd' command.
1. Pull code from upstream repository
- Make sure you are on master branch. To determine that, it should say 'git:(master)' next to your folder name. If it is not master branch, use the command 'git checkout master'.
- command 'git pull upstream master && git push origin master'. This will get any new changes from the main repository to your local folder, as well as pushing it to the fork repository in your profile
2. Create a branch
- Command 'git checkout -b branchName' to create a new branch (for example: git checkout -b test will create a test branch from master branch). -b means that we are creating a new branch, if you need to go to an existing branch, command 'git checkout branchName' (for eg: git checkout master will go to master branch). Check out wiki home page for branch naming convention.
3. Push code to branch
- After you have changes the codes and saved them, you will need to stage the changes and commit them before pushing.
- You can check the status using 'git status' command
- To stage the changed file, use 'git add fileName' command, such as 'git add index.html'. To add all changed files, use 'git add .'
- staging specifies the changes that you want to commit.
- To commit (actually changes it) the stages changes, use 'git commit -m "messagehere"' (for eg: git commit -m "fix a bug with index page"). '-m' specifies the message for the commit, and every commit needs a message. After committing, your chages have been set in local repository.
- Note: on VS Code, you can stage and commit your changes without needing to use command lines
- Push the code to your fork repository (origin) using 'git push origin branchName' with branchName being the name of the branch you are currently on.
4. Create a Pull Request
- After pushing to your fork repository, from your fork's github page, go to pull request and create a new pull request from your branchName to origin. Checkout home wiki page for pull request structure.
- After the pull request is accepted, pull the code from upstream again using 'git pull upstream master && git push origin master'.
- Git commands: https://confluence.atlassian.com/bitbucketserver/basic-git-commands-776639767.html
- Contributing to a project: https://akrabat.com/the-beginners-guide-to-contributing-to-a-github-project/