0

To keep my current feature branch in sync with development changes I have to do regularly:

git checkout development
git pull
git checkout <my feature branch>
git merge development

Is it possible to do this git commands sequence shorter?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Andriy Kryvtsun
  • 3,220
  • 3
  • 27
  • 41
  • 1
    I would just put that in a script / alias. – Oliver Charlesworth Aug 15 '17 at 23:09
  • i would recommend rebasing your feature branch rather than merging `git rebase development` on the last line: [more info on rebasing](https://stackoverflow.com/questions/804115/when-do-you-use-git-rebase-instead-of-git-merge) – sa77 Aug 16 '17 at 07:12

3 Answers3

0

You can always pull directly from the remote upstream branch if you'd like

git pull origin development  # Assuming you are on <my feature branch>

This will merge in changes from thedevelopment branch that exists on the remote server (origin in this case) that you keep in sync with into <my feature branch>

shiv
  • 206
  • 1
  • 7
0

Try this:

git config alias.sync '!git checkout development && git pull && git checkout feature && git merge development'

After adding that to your config, you can just do git sync.
(The exclamation point at the start tells git to execute the entire alias as a shell command).

You may also want to add some git stash in there before merging the development branch.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • Does this alias work only inside current repo or whole host? – Andriy Kryvtsun Aug 16 '17 at 15:14
  • @AndriyKryvtsun By default, [git config](https://git-scm.com/docs/git-config#_description) will only apply the alias on the current repo. If you want it to be available on all the repo's on your machine, add the [--global](https://git-scm.com/docs/git-config#git-config---global) option, as in `git config --global alias.*`. – Gino Mempin Aug 16 '17 at 23:27
0
git fetch origin development:development
git merge development
phd
  • 82,685
  • 13
  • 120
  • 165