0

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!

  • 1
    Add a cron to do `git fetch` and add a pre hook to check if is up to date on local. You cannot pull in background you can have conflict – Ôrel Feb 14 '22 at 13:22
  • Unless you're committing directly to a branch, I strongly advocate against ever checking it out, and I also suggest deleting local copies of shared branches as soon as you're done with them. For creating new branches and updating it with merge or rebase, I [recommend using origin instead](https://stackoverflow.com/a/71057049/184546). – TTT Feb 14 '22 at 22:36

1 Answers1

0

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

Hamza AZIZ
  • 2,582
  • 1
  • 9
  • 18