@devacademy/git-iam
v1.0.3
Published
Git extension for setting name and email config quickly
Downloads
5
Keywords
Readme
git-iam
This is a Git extension for setting local name and email configuration quickly.
It works by accessing a remote JSON file to get user information. The JSON file contains a list of name and email addresses of GitHub users. This extension configures the name and email config settings for the user provided in the current local repository. For more context, see the Applicability section.
Note about v0.2.0
Starting with version 0.2.0, the script also blanks out the global git config for user.name
and user.email
. We found some students would forget to run this script before committing and they would follow the git instructions to set the global user settings. Any future devs on that machine who also forgot to run this script before committing would unknowingly get the global settings. This change attempts to mitigate that scenario.
Version 1.0.2 makes a further change so that the behaviour described above only occurs if the --on-campus
flag is used during configuration since this behaviour is not ideal for people working from their personal machines.
Installation
yarn global add @devacademy/git-iam
# or
npm i -g @devacademy/git-iam
Create users.json
You need to create a JSON object that contains the students' GitHub information.
The users.json
file (or whatever you decide to call it) should have this format:
{
"jane": {
"name": "Jane Dev",
"email": "[email protected]"
},
"joe": {
"name": "Joe Dev",
"email": "[email protected]"
}
}
You can use the second part of this script to create the users.json. This script will automatically make a JSON object with the students' GitHub usernames as the object properties. Feel free to edit the property names.
Create Git Gist
- Open up Git Gist on Github
- You can either use the toolseda account or one of the teacher's personal account
- Create a new private Git Gist
- Copy the contents of your
users.json
and put it inside your new Git Gist - Get the shareable link of your private Git Gist
- Add
/raw/
to the end of the link
It should look like this
https://gist.github.com/{username}/{git-gist-id}/raw/
Configuration
In your terminal, run
# on-campus computer
git-iam --init https://gist.github.com/{username}/{git-gist-id}/raw/ --on-campus
# online student computer
git-iam --init https://gist.github.com/{username}/{git-gist-id}/raw/
Replace the link after the --init
with your Git Gist link
Note: --on-campus
should be used when setting up on a shared computer (this will clear the global git config when users use git iam <name>
)
This command
- saves the user list URL to the global Git config
users.url
- adds the
iam
alias to the global Git configalias.iam
Using git-iam
Now you can run this inside of an existing Git repository:
git iam jane
and it will have the same effect as running:
# if initialized with --on-campus only
------
git config --global --unset-all user.name
git config --global --unset-all user.email
------
# always run
git config user.name "Jane Dev"
git config user.email "[email protected]"
You can verify this by running:
git config --list
# or
cat .git/config
Now the next git commit
in this repo will list Jane as the dev on the commit.
Applicability
This might not seem like a justifiable effort - to build something that only saves such few keystrokes. And most people, who are the only devs using their computer, rarely run these commands.
But this is the config setting that dictates which developer (and GitHub user) performed the commit. In a classroom setting where students use every machine in the lab, this config is needed before each commit so the appropriate student gets credit for the commit (most importantly for their GitHub profile).
This script hopes to save our students a lot of time, and increase the accuracy of who is performing commits, so students get the credit they deserve.