1

Can running

git add .
git commit -m "message"

in a git repo which you've initialized using

git init

ever result in your code being sent to a repo that is not yours? I am concerned because I did this while not logged in to my git hub account.

yaboi
  • 301
  • 1
  • 6
  • 19
  • Aeehm...please what ?! – Zelldon Jun 22 '15 at 06:28
  • Please what? `git init` does not have anything to do with pushing? Please rephrase your question. – ckruczek Jun 22 '15 at 06:29
  • Also git is not github – Phil Jun 22 '15 at 06:33
  • git is not github, but when logged in and committing, git gives the message: "Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly: git config --global user.name "Your Name" git config --global user.email you@example.com After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author " and provides me with the username to my github account. So I felt this was relevant – yaboi Jun 22 '15 at 06:41
  • @yaboi This just means that Git is choosing a default name and email. It doesn't mean that any information left your local machine. – Tim Biegeleisen Jun 22 '15 at 06:42
  • 1
    I now understand that, my comment was in response to @Phil_1984_ to clarify why I mentioned my git hub account in my original question. – yaboi Jun 22 '15 at 06:43

2 Answers2

2

No, this (add and commit) is purely local to your repo.

You would need to add a remote (git remote add origin https://github.com/<user>/<repo>) and push (git push -u origin master) for that to happen (and you wouldn't have the right to push to a GitHub repo you don't own or you are not a collaborator of anyway).

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
2

Doing a git commit locally won't result in your code being sent to any repo, let alone a repo which is not yours. When you do a git commit, Git will add some local objects corresponding to the changes you have made in the current working branch.

In order for code to leave your local machine, you would need to issue a git push, which by default will try to send the master branch to whatever remote is contained in origin.

Even if you accidentally did a git push to an unknown repository, it would most likely be rejected for many reasons. First, in the case of GitHub, you would not have to rights to make the push. Even if you somehow did have the right to push, either the branch names might not be the same, or it would be rejected as not being a fast forward.

Git has many safeguards to prevent this sort of thing from happening.

Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263
  • Possible edit to this answer based on @VonC's response. The push would definitely be rejected because "you wouldn't have the right to push to a GitHub repo you don't own or you are not a collaborator of anyway" – yaboi Jun 22 '15 at 06:57
  • 1
    Updated my answer...thanks for the detailed information. – Tim Biegeleisen Jun 22 '15 at 07:01