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:
- You make changes in your local repository.
- You stage the changes with
git addand commit them withgit commit. - 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 bemasteror 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:
git fetch→ gets changes from the remote repository.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
| Operation | Direction | Purpose |
|---|---|---|
| Push | Local → Remote | Send your committed changes to the remote repository. |
| Pull | Remote → Local | Update 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
| Command | Description |
|---|---|
git push | Push your commits to the remote repository. |
git push origin main | Push your commits specifically to the main branch on origin. |
git pull | Pull and merge changes from the default remote repository. |
git pull origin main | Pull 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:
- You add new automation for configuring routers.
- You commit it locally:
git add router-config.py git commit -m "Add automated router backup script" - You push to remote:
git push origin main - Your teammate wants the latest changes, so they pull:
git pull origin main - 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
- Sequence matters: Always commit → pull → push.
- Conflicts: Know that conflicts happen if multiple people edit the same file; Git requires manual resolution.
- Branch awareness: You can push or pull from specific branches (
main,dev,feature-x). - Origin: Default remote repository is usually called
origin. - 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.
