Syncing your Local and Remote Repos: The Pull Command
Sometimes the code in your remote repo will contain commits you do not have in your local repo.
In those situations, if you attempt to push from the local to the remote, Git will respond with a “![rejected]” error.
Solution: you need to pull the commits from the remote repo into your local repo.
The pull command fetches commits from the remote repository into your local repo, and then merges the changes into the current branch of your local repo.
(The pull command does a fetch and merge in a single step.)
In this way, the local and remote repos are synchronized.
Here’s the version of the pull command we will use:
git pull origin master --no-edit
This will pull the changes from the remote and merge them into the current branch (master, in this case), and then push commands will succeed.
Important: your local repo must be up-to-date, so commit your local changes before running a pull command.
How to Exit the Vim Editor (:q)
If you omit the --no-edit
part of the pull command, Git may start a text editor called Vim. If your screen looks similar to this, you are in Vim:
To exit the Vim editor and return to the shell, type this command and hit enter:
:q