Push/pull

Utilize common version control operations with Git

📘Cisco DevNet Associate (200-901 DEVASC)


Git is a version control system used to track changes in code, configuration files, scripts, and other text-based IT resources. Two of the most important operations in Git are push and pull, which let you sync changes between your local system and a remote repository (like GitHub, GitLab, or Bitbucket).


1. Remote Repository vs Local Repository

Before we talk about push and pull, you need to understand these terms:

  • Local Repository – The copy of the code or files on your computer. You can make changes, add files, or delete files here.
  • Remote Repository – The copy of the code or files on a server or cloud platform (GitHub, GitLab, etc.) that multiple people can access.

Think of it as:

  • Your local repo = your workspace.
  • Remote repo = shared storage where your team can access your changes.

Push and pull are operations that sync these two repositories.


2. Git Push

Definition:
git push sends your local commits (changes you saved in your Git history) to the remote repository.

Why it is important:

  • Keeps the remote repository up to date.
  • Allows team members to see your changes.
  • Lets automated systems (like CI/CD pipelines) access the latest code.

How it works:

  1. You make changes in your local repository.
  2. You stage the changes with git add and commit them with git commit.
  3. You push your commits to the remote repository using:
git push origin main
  • origin → the default name for the remote repository.
  • main → the branch you are pushing to (it could also be master or any other branch).

Key points for the exam:

  • You cannot push without committing changes first.
  • If someone else updated the remote repo before you pushed, Git will reject your push. You must pull first.

3. Git Pull

Definition:
git pull fetches changes from the remote repository and merges them into your local repository.

Why it is important:

  • Keeps your local copy up to date.
  • Prevents conflicts when multiple people work on the same files.
  • Ensures you are working on the latest version of the project.

How it works:

git pull origin main
  • origin → the remote repository.
  • main → the branch you want to update.
  • Git fetches all changes and automatically merges them into your local branch.

Key points for the exam:

  • Pull is a combination of two commands:
    1. git fetch → gets changes from the remote repository.
    2. git merge → merges those changes into your local branch.
  • If changes conflict with your local edits, Git will prompt you to resolve conflicts.

4. Push vs Pull – Quick Comparison

OperationDirectionPurpose
PushLocal → RemoteSend your committed changes to the remote repository.
PullRemote → LocalUpdate your local repository with changes from the remote.

Remember:

  • Always pull before you push to avoid conflicts.
  • Push requires write access to the remote repo. Pull usually requires read access.

5. Common Git Push/Pull Commands

CommandDescription
git pushPush your commits to the remote repository.
git push origin mainPush your commits specifically to the main branch on origin.
git pullPull and merge changes from the default remote repository.
git pull origin mainPull and merge changes from the main branch of origin.

6. Example Scenario in IT Environment

Imagine you work on a network automation script stored in Git:

  1. You add new automation for configuring routers.
  2. You commit it locally: git add router-config.py git commit -m "Add automated router backup script"
  3. You push to remote: git push origin main
  4. Your teammate wants the latest changes, so they pull: git pull origin main
  5. Now, both of you have the latest script in your local repo.

This ensures the team stays in sync and the remote repository is always updated.


7. Exam Tips

  1. Sequence matters: Always commit → pull → push.
  2. Conflicts: Know that conflicts happen if multiple people edit the same file; Git requires manual resolution.
  3. Branch awareness: You can push or pull from specific branches (main, dev, feature-x).
  4. Origin: Default remote repository is usually called origin.
  5. Automation impact: Push triggers CI/CD pipelines or automated tests if configured.

Summary for Students

  • Push = send your changes to remote.
  • Pull = get latest changes from remote.
  • Always commit first.
  • Conflicts can happen, and you must resolve them.
  • Branches and remotes define where you push or pull.
Buy Me a Coffee