Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity,and support for distributed, non-linear workflows.
Git: Prevent commits in master branch
- Go to your repository.
- Create file .git/hooks/pre-commit with following content:
#!/bin/sh branch="$(git rev-parse --abbrev-ref HEAD)" if [ "$branch" = "master" ]; then echo "You can't commit directly to master branch" exit 1 fi
- Make it executable (not required on Windows):
$ chmod +x .git/hooks/pre-commit
To disable fast-forward merges you must also add following option to your .git/config file:
[branch "master"]
mergeoptions = --no-ff
If you want also protect master branch on your remote, check this answer: How to restrict access to master branch on git
GIT: Prevent pushing to master
#!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
read -p "You're about to push master, is that what you intended? [y|n] " -n 1 -r < /dev/tty
echo
if echo $REPLY | grep -E '^[Yy]$' > /dev/null
then
exit 0 # push will execute
fi
exit 1 # push will not execute
else
exit 0 # push will execute
fi
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
read -p "You're about to push master, is that what you intended? [y|n] " -n 1 -r < /dev/tty
echo
if echo $REPLY | grep -E '^[Yy]$' > /dev/null
then
exit 0 # push will execute
fi
exit 1 # push will not execute
else
exit 0 # push will execute
fi
------------------------------------------------------------------------------------------------
----------------
git pull
git fetch --prune
git reset --hard @{u}
git stash
git stash pop
git status
git push
git log
q or shift + q --> for exist
git log --stat --oneline > ./ss.txt
git dif commt1..commt2
---for automatic branching
git flow init Initialized empty Git repository in ~/project/.git/ No branches exist yet. Base branches must be created now. Branch name for production releases: [master] Branch name for "next release" development: [develop] How to name your supporting branch prefixes? Feature branches? [feature/] Release branches? [release/] Hotfix branches? [hotfix/] Support branches? [support/] Version tag prefix? []
git branch * develop master
--------------------------------------------------------------------------
No comments:
Post a Comment