Ryan Lyu
Ryan Lyu

Reputation: 5135

GitFlow: Is there a way to automatically keep my local master/develop branches synced with remote branch?

My workflow is as follows:

  1. checkout a new branch feature/foo from develop.
  2. implement this feature
  3. push feature/foo Github
  4. squash merge this feature to develop branch through the GitHub Pull Request menu.

Usually, I never merge any commits to master/develop branches in local.

I have two local branches, which always pull from the origin, and never be pushed.

My question is, is there a software or command-line tools to automatically sync that two branches with origin server at a certain interval and keep them fresh, so I don't have to pull them manually and save the time.

Upvotes: 1

Views: 547

Answers (2)

scipilot
scipilot

Reputation: 7457

In the scenario where your local develop and master are "slaves" of the remote, I find it quicker to just delete the local branch and recreate it from the fetched remote branch. I even do this when working in a team and we do merge locally into develop. Before merging I throw away develop and check it out again from origin/develop with the other team members latest changes fetched.

Most clients (SourceTree, Git Extensions, Tower) feature an automated fetch. Therefore you only need to script the "delete and create-branch" from the locally fetched remote branch which will be always fresh.

As others have mentioned the issue of conflicts means no software would include an automated pull (fetch + merge). But automated fetch alone is risk-free, so most do include that.

However - why bother even keeping a local branch if you're never going to use it? Why not just create your local feature branches from the remote branch?

e.g. you create a new branch feature/foo from origin/develop instead. With auto-fetch, it will always be up to date.

Upvotes: 2

Noufal Ibrahim
Noufal Ibrahim

Reputation: 72795

You can write a small script to automate it. However, what will you do if your branch has a merge conflict with develop when you try to merge back? How do you resolve it? Ideally, you should pull in changes from develop into your own branch, make sure it works and then push it back rather than rely on automation or the GitHub website controls.

Upvotes: 1

Related Questions