Skip to content

Instantly share code, notes, and snippets.

@celsowhite
Last active January 16, 2019 21:04
Show Gist options
  • Save celsowhite/687a398c735d93ed9fbb33927f2c0f70 to your computer and use it in GitHub Desktop.
Save celsowhite/687a398c735d93ed9fbb33927f2c0f70 to your computer and use it in GitHub Desktop.
Celso White LLC git workflow and collaboration.

Overall Points

  • Never develop directly on master. Always do your changes on a feature branch.
  • Primary tasks of merging pull requests and deleting remote feature branches should be done by the project owner/person with access to the clients FTP.

New developer on project. Needs to clone repo and start a fresh new feature branch.

Go into the folder where you want this repository to be on your computer. I.E for Wordpress projects the themes folder. The below command will bring down all of the most recent code from the repository and position you on the master branch.

git clone 'repo-url'

Go into the repo folder that was just created for you

cd 'repo-folder-name'

Create new feature branch. Always do this command while on the master branch so we are starting with the most updated code. This implies that a new branch will be created using the code from the current branch you are on.

git checkout -b 'feature-branch-name'

Work on your feature branch by adding unstaged files and commiting descriptive messages about changes being made.

git status

git add .

git commit -m "Your message."

Push your local changes to a remote branch within the repo. Allows other developers to view what you are working on and test it out.

git push origin 'feature-branch-name'


Master branch has been updated while you are working on your feature.

The usual case for this is that another developer is working on another update at the same time. Your local branch is not up to date so you need to sync it before doing your pull request.

List the local branches just to orient yourself as to what branches you have and which you are on

git branch

Checkout master to get the most up to date code.

git checkout master

git pull origin master

Go back into feature branch to merge it with master

git checkout 'feature-branch-name'

git merge master

At this stage there may be some merge conflicts if developers were working on the same files. Fix them up and do a commit.

git add .

git commit -m "Your message"

git push origin 'feature-branch-name'


Issue a pull request so that other developers can check out your new features.

Once done with the feature, issue a pull request in the remote repository. This is done via the online interface in Bitbucket or Github. Describe what has been updated.

Other developers will test your features locally and we'll add comments directly on the pull request if something should be changed. See below section for 'Testing out another developers features.'

If there are comments on the pull request keep working on the feature locally and push back to origin 'feature-branch-name' The pull request will auto update with the changes


Testing out another developers features.

Normal use case is when the main project holder is testing updates before merging a pull request. Pull Requests should be reviewed by everyone but one person should be in charge of the actual merge.

Step 1

Fetch the remote info so we are up to date. Then create a new local branch based off of the remote branch you want to test. Merge master into your local version of the branch to make sure there are no conflicts (the person who issued the pull request should have merged master into their remote branch).

Checking out the branch will automatically switch the code in your code editor and subsequently the site appearance.

git fetch origin
git checkout -b local-feature-branch-name origin/remote-feature-branch-name
git merge master

Step 2

When the feature is ready then update local master and push up to the origin master.

git checkout master
git merge --no-ff local-feature-branch-name
git push origin master

Feature is done and merged.

It's now safe to delete the local and remote branches of that feature. List the local branches just to orient yourself as to what branches you have and which you are on

git branch

Delete the branch from the remote. Leave this up to the main holder of the repository.

git push -d origin <branch_name>

Delete the local feature branch

git branch -d 'feature-branch-name'


Resources

Really helpful links to learn more about git workflow and collaboration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment