DEV Community

Muhammad Shakkeer
Muhammad Shakkeer

Posted on

Git push , fetch , merge and pull understand in simple way

Here's a beginner-friendly comparison of Git commands push, pull, fetch, and merge in a tabular format along with their real-life developer situations:

Command Description Real-Life Developer Situations
git push <remote> <branch> Sends local commits to a remote repository. - Sharing your changes with the team on GitHub/GitLab/Bitbucket.
git pull <remote> <branch> Fetches changes from the remote and merges them - Updating your local repository with changes made by other team members.
git fetch <remote> Fetches changes from the remote but doesn't merge - Checking what's new in the remote repository without merging it.
git merge <branch> Merges changes from a different branch - Combining changes from a feature branch into the main development branch.

Explanation:

  • git push <remote> <branch>:

    • Sends your committed changes from the local repository to a remote repository (e.g., GitHub).
    • Real-Life Situation: Sharing your completed feature or bug fixes with your team by uploading changes to the central repository.
  • git pull <remote> <branch>:

    • Fetches changes from a remote repository and merges them into the local branch.
    • Real-Life Situation: Updating your local codebase with the latest changes made by other team members on the shared repository.
  • git fetch <remote>:

    • Retrieves the latest changes from the remote repository but does not merge them into the local branch immediately.
    • Real-Life Situation: Checking for updates in the central repository without merging them into your working branch immediately.
  • git merge <branch>:

    • Integrates changes from a different branch into the current branch.
    • Real-Life Situation: Combining changes from a feature branch into the main development branch or integrating updates from a release branch.

These commands help developers collaborate, keep their local repositories up-to-date with the central repository, and manage code changes effectively by sharing, fetching, and merging code between local and remote repositories in a team setting.

Top comments (0)