Can git ever send your code to a repo that isn't yours?

200 views Asked by At

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.

2

There are 2 answers

1
Tim Biegeleisen On BEST ANSWER

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.

0
VonC On

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).