Skip to content

Instantly share code, notes, and snippets.

@amgohan
Last active April 28, 2017 05:25
Show Gist options
  • Save amgohan/a0c8d8f0368332de192c6a4f9a247ee8 to your computer and use it in GitHub Desktop.
Save amgohan/a0c8d8f0368332de192c6a4f9a247ee8 to your computer and use it in GitHub Desktop.
add user and email automatically to cloned project
#!/bin/bash
echo "enter your git user.name"
read user_name
echo "enter your git user.email"
read user_email
cat > /bin/gitclone <<- EOM
#!/bin/bash
set -e
git clone \$1
PROJECT_NAME=\$(echo \$1 | sed -n 's#.*/\([^.]*\)\.git#\1#p')
echo "\$PROJECT_NAME cloned"
cd \$PROJECT_NAME
git config user.name "${user_name}"
git config user.email "${user_email}"
EOM
chmod +rx /bin/gitclone
@amgohan
Copy link
Author

amgohan commented Apr 28, 2017

Motivation

I have my work account configured as global user and email. But for my own freetime projects I add the user and email manually to the project scope. But when I forget to add them I commit with my work account into my own repos 👎 .
This script helps me to add my name and email when I clone a new project for the first time.

How to install

wget https://gist.githubusercontent.com/amgohan/a0c8d8f0368332de192c6a4f9a247ee8/raw/5b32bb68e90cafffa4c987198b718ca54045e844/gitclone.install && chmod u+x gitclone.install
sudo ./gitclone.install
# provide user and email for your git project
rm -f gitclone.install

Usage

gitclone <your_repo_here>

this will add the section [user] in your project .git

[user]
	name = <your_name_here>
	email = <your_email_here>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment