Skip to content

Commit

Permalink
Set author from git config in setup script.
Browse files Browse the repository at this point in the history
This will automatically set the author of the first commit to the name
and email that is set in the global git config. For most situations this
should be what you want. The option to specify a different author
remains for the cases where a different behaviour is desired.
  • Loading branch information
bsamseth committed Oct 10, 2018
1 parent 039e3db commit c0b42dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ the [setup script](setup.sh) as follows:
``` bash
$ git clone https://github.com/bsamseth/cpp-project # Or use ssh-link if you like.
$ cd cpp-project
$ sh setup.sh "Your Name <your@email.com>"
$ sh setup.sh
```
The result is a fresh Git repository with one commit adding all files from the boiler plate.

5 changes: 4 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ git reset "$(git rev-list --max-parents=0 --abbrev-commit HEAD)"

git add --all

name=$(git config user.name)
email=$(git config user.email)

# If this script is called with an argument, use that as the amended author
# EX: ./setup.sh "Author Name <author_email@email.com>"
if [[ "$1" ]]; then
git commit --amend --author="$1"
else
git commit --amend # Will prompt for message.
git commit --amend --author="$name <$email>"
fi

0 comments on commit c0b42dc

Please sign in to comment.