DEV Community

Cover image for 10 More Git Tricks That You Should Know

10 More Git Tricks That You Should Know

Jacob Herrington (he/him) on August 14, 2019

Cover Image: Two People Holding Macbook Pro by Christina Morillo I recently wrote an article called 10 Git Tricks to Save Your Time and Sanity. Peo...
Collapse
 
vimmer9 profile image
Damir Franusic

I use the following scripts to generate some common files. Although they work, you will probably need to tweak them to meet your needs.

CHANGELOG

#!/bin/bash
git log  --decorate --tags --no-walk > CHANGELOG 2>&1 || { echo "git repository not found!" > CHANGELOG; }

VERSION

#!/bin/bash

# Tag revisions like this:
# $ git tag -a -m "Version 0.2" v0.2 HEAD

VF=VERSION
DEFAULT_VERSION=v1.0

LF='
'
TAG_TYPE="v*"

# First see if there is a version file (included in release tarballs),
# then try git-describe, then default.
if test -d .git -o -f .git &&
    VN=$(git describe --abbrev=4 --long --match=$TAG_TYPE HEAD 2>/dev/null) &&
    case "$VN" in
    *$LF*) (exit 1) ;;
    v[0-9]*)
        git update-index -q --refresh
        test -z "$(git diff-index --name-only HEAD --)" ||
        VN="$VN-mod" ;;
    esac
then
        continue
    #VN=$(echo "$VN" | sed -e 's/-/./g');
else
    VN="$DEFAULT_VERSION"
fi

#VN=$(expr "$VN" : v*'\(.*\)')

# Show the version to the user via stderr
echo >&2 "$VN"

# Parse the existing VERSION-FILE 
if test -r $VF
then
    VC=$(sed -e 's/^version: //' <$VF)
else
    VC=unset
fi

# If version has changed, update VERSION-FILE
test "$VN" = "$VC" || {
    echo "$VN" >$VF
    echo >&2 "($VF updated)"
}

AUTHORS

#!/bin/bash
echo -e "Original Author\n===============\nDamir Franusic <damir.franusic@gmail.com>" > AUTHORS
CONTRIBUTORS=`git log --format='%aN <%aE>' | sort -f | uniq | grep -v "Damir Franusic"`
if [ ! -z "$CONTRIBUTORS" ]; then
    echo -e "\nContributors\n============\n$CONTRIBUTORS" >> AUTHORS
fi
Collapse
 
jacobherrington profile image
Jacob Herrington (he/him)

Wow! Thanks for sharing 👌

Collapse
 
alikhani97 profile image
Mahdi Alikhani

Thanks for sharing !

Collapse
 
jacobherrington profile image
Jacob Herrington (he/him)

No problem, hope it's useful 🤠

Collapse
 
alikhani97 profile image
Mahdi Alikhani

it's useful for me a lot, 🤠.

Collapse
 
matthewpersico profile image
Matthew O. Persico

1) You have a couple of typos "snipped" instead of "snippet".
2) $7 is nice, but what I really want is a list of branches that are part of Pull Requests that have been remotely merged. I think you have to use a GitHub API to do that, though.

Collapse
 
jacobherrington profile image
Jacob Herrington (he/him)

Thanks for the typo callout!

Yeah, I'm not sure on that one. Maybe hub could be helpful?

Collapse
 
nqthqn profile image
nqthqn

I like the co author trick

Collapse
 
jacobherrington profile image
Jacob Herrington (he/him)

It's really useful! I pair a lot so it's nice to be able to include others on the commits we write together.

Collapse
 
vlasales profile image
Vlastimil Pospichal • Edited
Collapse
 
jacobherrington profile image
Jacob Herrington (he/him)

Thanks for sharing!

Collapse
 
parinay profile image
parinay

Thanks !

Collapse
 
mxoliver profile image
Oliver

Oh man that command to create a new repo from a directory is a god send. Thanks so much for writing this