Thursday, September 12, 2019

Git

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



  1. Go to your repository.
  2. 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
    
  3. 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

pre-commit
#!/bin/sh
# prevent commit to local master branch
branch=`git symbolic-ref HEAD`
if [ "$branch" = "refs/heads/master" ]; then
echo "pre-commit hook: Can not commit to the local master branch."
exit 1
fi
exit 0

pre-push
#!/bin/sh
# Prevent push to remote master branch
while read local_ref local_sha remote_ref remote_sha
do
if [ "$remote_ref" = "refs/heads/master" ]; then
echo "pre-push hook: Can not push to remote master branch."
exit 1
fi
done
exit 0


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


------------------------------------------------------------------------------------------------

git commands
----------------
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
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

Encrypt/Decrypt the App.Config

Program.cs using System; using System.Diagnostics; using System.IO; namespace EncryptAppConfig {     internal class Program     {         pr...