Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Git know which repository to push to?

I'm a complete noob when it comes to version control, but I recently started using GitHub to host some of my projects. I blindly use the command git push origin master to push changes to either of the two repositories. I don't understand how Git knows which repository to push to. I use the same command to push to each. Does the directory I'm in have anything to do with it?

Thanks for clearing this up for me.

like image 769
ICoffeeConsumer Avatar asked Sep 26 '12 04:09

ICoffeeConsumer


People also ask

How does GitHub know that I am allowed to push to a specific repo?

By default only the owner of the repository has write access. If you can push to your own repo, it's because you are using one of the supported authentification methods (HTTPS, SSH, ...). If you want to grant someone else privileges to push to your repo, you would need to configure that access in the project settings.

How does push work in git?

The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches.

How do you change the repository you are pushing to?

You will need to 1) fork the project you want to make changes to into your own github account, 2) clone that forked repo to your local, 3) make changes, 4) push to your own repo.

Where does git push default to?

If you run the simple command git push , Git will by default choose two more parameters for you: the remote repository to push to and the branch to push. By default, Git chooses origin for the remote and your current branch as the branch to push.


1 Answers

A word of advice, "blindly use"ing anything is a bad idea.

git has a system of remotes which allows to specify URLs and transports to repositories other than the one where you're working. git push origin master pushes the current branch to the remote called origin as the branch master. You have a remote called origin. This is created by default when you clone a repository from a URL.

like image 59
Noufal Ibrahim Avatar answered Sep 18 '22 05:09

Noufal Ibrahim