Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between git push and git pull?

I just stumbled over something peculiar today. I asked a co-worker at my summer job to help me set up a new remote git repo for my code and there was a lot of confusion about what he did and what I wanted to do. I asked him to send over his config to be able to see the path to his remote and found out that he didn't have a remote. When I asked him about this he explained his workflow like this:

  1. Change something locally
  2. Commit
  3. Move to remote dir
  4. git pull c:\localdir

So instead of pushing to a remote he constantly pulled from his local repo to the one on our server. Sort of working backwards. When I confronted him about this he asked me what the difference was and I could not really answer him, but I think there are something right?

So my question to you all is: What is the difference in pushing to a remote and pulling from a remote?

like image 825
Qw4z1 Avatar asked Jun 28 '12 08:06

Qw4z1


People also ask

What is difference between push and pull in git?

git pull is one of many commands that claim the responsibility of 'syncing' remote content. The git remote command is used to specify what remote endpoints the syncing commands will operate on. The git push command is used to upload content to a remote repository.

What is the difference between a push and pull?

Force: Push and Pull A force that changes the direction of an object towards you, would be a pull. On the other hand, if it moves away, it is a push.

What is GitHub pull and push?

Pull requests let you tell others about changes you've pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch.


2 Answers

Pushing to a remote : send some commits you have to a another git repo. The git repo is considered as "remote", but it can be a repo in another folder of your hard drive. pulling from a remote : get some commits from a remote repo and merge them in your current HEAD (your current checkout of your repo)

Your coworker might have use pull instead of push because your repository might not have been available (no git daemon running, or gitweb, or ssh server on), but his was avalaible from your computer. As it is a server, he might not want to expose a git daemon/service which could be a vector of attack.

But if your repository was shared/available, he would just have been able to do :

  1. change something locally
  2. commit
  3. push to your repository
like image 121
Dolanor Avatar answered Sep 28 '22 03:09

Dolanor


In my view you can either let users push their commits to some repository that's considered to be "the master", or you let them send pull requests to a single user that has permission to modify said "master".

Github, for example, won't let non-contributors push to the repository, but will allow them to send pull requests, so that the contributors can integrate their changes.

like image 28
Miquel Avatar answered Sep 28 '22 03:09

Miquel