Can I associate a GitHub user with his commits by name only, BitBucket-style? - github

I've seen Github shows name instead of a linked username in commits and I realise that the right thing to do is to link by email. However, I already have a repository with a whole bunch of commits whose email is "none#none".
On BitBucket, I can specify a per-project mapping of committer name to BitBucket account, and this has worked well enough. Is there anything like this on GitHub?
If not, what other options are there, short of leaving the commits unlinked and rewriting the entire history?

You can use .mailmap file in your repo, for mail aliased (as stated in "“Alias” git authors/committers?")
You also can add another email in your Email setting account.
But both solutions don't scale well when several authors use the same none#none email.

Related

Why am I able to push and send/receive pull requests but not on the contributor list in github?

I'm been working in a team of four. I'm in the collaborator list. I'm able to commit, push, send pull requests and merge in our repo. My teammates can see my changes, but everyone is on the contributor list except me.
I double checked my email address, make sure the email I used in my local setting is the same with my default email in the github account.
We have changed the owner of the project once, and I'm still using the old url. Is this the reason for that?
I found the github has a complex rule for you be considered as a contributor. Here's the doc of it.
https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/managing-contribution-settings-on-your-profile/why-are-my-contributions-not-showing-up-on-my-profile
You have to commit to the main/default branch or make pull requests. To commit into other branches won't count.
Also, to use the old project url is definately one problem. In the project insight, everyone's profile is linked with their username. While mine is only a username with no user icon.
I think I just accidentally hit into one of the corner cases, but I'm still very confused of this design pattern.

Do you lose contributions of a project if you get removed from this project?

I can't seemed to find this information anywhere, but just wanna ask that if you are a contributor of a project and you worked on it so you can see all of those contributions on the chart, but then for whatever reason the owner of the project removed you, do you lose all of those contributions? as in will those green contribution grids(the days you work on it) go back to grey?
No, the contributions are based on the commit email ID, and do not have anything to do with the corresponding GitHub account having access to the repository. GitHub attributes a commit to a particular account if the email ID used with the commit is registered under that account.
So, unless the email IDs of past commits are in some way changed later, the contributions will still be visible, as long as the repository is public.
This also works the other way around. Anyone can set any email ID in their git configuration while committing, so it is trivial to falsely attribute commits to someone else, when viewing the contribution chart in GitHub.

Github transfer contributions from one account to another

I have googled it a lot but didn't find any clear answer if it possible and how to do it.
I have an account from which I have contributions to a private repo. I don't have any repositories.
I want all those contributions to go to my new account (There I have repositories).
Is that possible? Do I still have access to that private repo after transfer the contributions?
You would need to rewrite commits which would create new hashes (the committer's name is part of the data used to calculate the hash).
This would mean all commits that reference these commits (the parent commits also being part of the data used to calculate the hash) would also need to be regenerated (rebase allows this to be done in bulk).
All of this would require forcing pushes as well (so all other contributor's local repositories are going to be impacted).
Even if github can automate some of this, it is a massive impact.
TL;DR: yes, but you probably should accept it is hard to rewrite history.
Guessing from the tags I assume you're talking about GitHub accounts. GitHub calculates contributions based on the author email address used in Git commits, and if there is a GitHub account that uses this email address, your GitHub user name shows up as a contributor. That said, you can associate multiple email addresses with a single GitHub account. So if you unregister your current email address from your old GitHub account, and register the same email address for your new GitHub account, existing contributions will show under your new GitHub account.
Do I still have access to that private repo after transfer the contributions?
That's a totally different question, and the answer depends on whether your new GitHub account was given access to the private repository. The GitHub permissions system is based on the GitHub user name, not on registered email addresses.

Adding default reviewers to Github repository

I followed the instructions here https://help.github.com/articles/about-codeowners/ but it doesn't seem to work. I even added the CODEOWNERS file at both the root and .github directory. The reviewers specified in the CODEOWNERS file are not selected automatically when a pull request is created. See screenshots below. Onyone who has set this up, could you point to where the problem is. Thank you.
You need to be sure that your base branch has:
the 'Protect this branch' flag activated
the 'Require pull request reviews before merging' flag activated
the 'Require review from Code Owners' flag activated
Then in the CODEOWNERS file, located either in the root of the repo or in the .github subfolder, you need to have either a user described with '#user', a user described with his email like 'user#domain.com', or a team described with '#org/teamname'.
You will need also to be sure that:
your contributors (users and teams) have for each of them the 'write' access to the repo
the team is not a 'secret' team, only the 'visible' teams would be taken into account
Double-check the CODEOWNERS file syntax
The pattern is followed by one or more GitHub usernames or team names using the standard #username or #org/team-name format.
(I don't see # in your case)
You can also refer to a user by an email address that has been added to their GitHub account, for instance user#example.com.
If the syntax is correct, then you can contact GitHub support to have them investigate.
The OP Pratheep actually find this is working:
You need the # and referring to my last screenshot above, you don't see the reviewers in the list when creating the PR.
But once the PR is created, then you will see the reviewers in the list.
I believe it was by design not to show. Because if you show the reviewers in that list before the PR is created, the names can be removed.
This way no one can create a PR without notifying the codeowners/default reviewers.

I've added lots of lines to github project, why does it say I only added two?

Have a look at the contributors page for this project:
https://github.com/Sahand1993/CraigslistPrice/graphs/contributors?from=2018-04-22&to=2018-05-14&type=a
My username is Sahand1993. If you look at my graph, it says I've only added 2 lines of code. But if you look at the project file called elasticsearch/searcher.py, you'll see that I added that entire file, which is around 200 lines long!
So, why is Github saying I've only added 2 lines?
GitHub matches commits to users via the email address in the commit. You haven't set your email address properly.
I see several commits from sahandzarrinkoub#n157-p198.eduroam.kth.se and sahandzarrinkoub#Sahands-MBP.lan, but only one from sahandz#hotmail.com. This last email address is the one you've registered with GitHub.
If the other email addresses are real email addresses that you own you can add them to your GitHub account and claim those commits. But I don't think they are (certainly the one #Sahands-MBP.lan doesn't look right).
I suggest
Adding any email addresses you plan on using to your GitHub profile.
Setting your email address properly on those two machines, e.g. via
git config --global user.email "sahandz#hotmail.com"
This will enable GitHub to associate new commits with your account.
Adding a .mailmap file to map the wrong email addresses to the correct email address.