Skip to content
Advertisement

Difference between sudo git pull and sudo git pull git@bitbucket.org:user/project.git

I’m trying to pull code off a remote bitbucket repository to my master branch on Linux server. Don’t understand the difference between the following 2 approaches to pulling code (connecting to bitbucket via SSH):

sudo git pull origin master

sudo git pull git@bitbucket.org:username/project_name.git master

Both approaches seem to update the local master branch (on Linux server) with code from the remote master branch. So what’s the difference between the two pull formats and which is the better approach to doing a git pull while connecting via SSH?

Advertisement

Answer

Firstly, you do no need to use sudo if you have permission to the local directory where is your repository.

The first way is used with a repository you’ve added as a remote. This is the recommanded way to do it. You can add it as a remote with the following command:

git remote add origin git@bitbucket.org:username/project_name.git

Then, you can check your remote has been added with:

git remote -v

So you’ll just have to pull with the command, from the remote named origin:

git pull origin master

The second way is used with the clone subcommand only to clone from a remote URL. With pull, it is less repetitive to use the saved remote and the remote can be tracked by your git client to check if pull or push is needed.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement