How to Push Code from Local to Remote Repository

The git push command is used to send or upload the changes made in the local repository to a remote repository.

Before you can push code from your local repository to the remote repository, you must complete these three steps:

  1. First add files using the 'git add .' command. The '.' dot after 'git add' command saves updates of multiple or all files for the next commit. However, you can also save updates of a single file using 'git add file_name' command. For example:

  2. git add .

  3. Next, commit the changes using the git commit -m 'commit message' command:

  4. git commit -m 'initial commit'

  5. Finally, push the commit to the remote repository using the 'git push origin remote_branch_name' command:

  6. git push origin develop

    Note: If multiple developers are working on the same branch, you must ensure that your current local branch has the latest updates from its remote counterpart. Your updates will be rejected if the tip of your current branch is behind its remote counterpart. Therefore, it is recommended to update your current local branch before pushing it to the remote branch using the 'git pull origin remote_branch_name' command. For example:

    git pull origin develop

    After pulling updates from the remote branch, sometimes conflicts may arise if two or more separate branches have made edits to the same file when working in a team environment. Git will marked the files as being conflicted and will not let you push your updates to its remote counterpart. It is then your responsibility to resolve the conflicts.