Home > Software design >  Git: Keep all branches up to date
Git: Keep all branches up to date

Time:02-15

guys! I've got recently a DevOp position on a small company and one of my first tasks sound like this:

Most usual scenario is that a dev works on a branch, then switches branch to do a hotfix and forgets to do a git pull before making changes or before creating a new branch off that particular branch.

I would like to know how can I reach that goal, to sync their work in case of forgetting to use git pull by one of our devs.

  • We're using Jenkins if it can help us to reach our goal.

Thank you!

CodePudding user response:

i think what you're looking for is git hooks from GIT doc

Like many other Version Control Systems, Git has a way to fire off custom scripts when certain important actions occur. There are two groups of these hooks: client-side and server-side. Client-side hooks are triggered by operations such as committing and merging, while server-side hooks run on network operations such as receiving pushed commits. You can use these hooks for all sorts of reasons.

for your use case, I think the best one is to use the post-checkout hook

so when someone switch or do a checkout a bash script will run

to test this, go to a git folder and run

echo '#!/bin/sh' > .git/hooks/post-checkout
echo "echoed by git hook" >> .git/hooks/post-checkout

make the file executable

chmod x .git/hooks/post-checkout

and try to switch to a branch, you'll see the content "echoed by git hook" displayed

  • Related