Skip to content

Synchronizing with Remote Repositories

Git allows the users to perform operations on the Repositories by cloning them on the local machine. This will result in the creation of various different copies of the project. These copies are stored on the local machine and hence, the users will not be able to sync their changes with other developers. To overcome this problem, Git allows performing syncing of these local repositories with the remote repositories. This synchronization can be done by the use of two commands in the Git. These commands are:

Push

This command is used to push all the commits of the current repository to the tracked remote repository. This command can be used to push your repository to multiple repositories at once.

$ git push -u origin master

To push all the contents of our local repository that belong to the master branch to the server (Global repository). If you want to push some other branch

$ git push -u origin <branch-name>

Pull

Pull command is used to fetch the commits from a remote repository and stores them in the remote branches. There might be a case when other users perform changes on their copy of repositories and upload them with other remote repositories. But in that case, your copy of the repository will become out of date. Hence, to re-synchronize your copy of the repository with the remote repository, the user has to just use the git pull command to fetch the content of the remote repository.

$ git pull origin master

If you want on different branch and want to pull changes from that branch

$ git pull origin <branch-name>
Back to top