Once your local repository is connected to a remote on GitHub, you transfer commits back and forth using git push (uploading local changes to the cloud) and git pull (downloading cloud updates into your local machine).
git pushThe git push command exports commits from your local repository to a branch on the remote server.
-u)The very first time you push a newly created branch to a remote, you must tell Git which remote branch should track your local branch:
-u (or --set-upstream) flag do?main branch to the remote branch origin/main.origin main. You can simply type:git pull vs. git fetchWhen working in a team or across multiple computers, teammates will push new commits to GitHub. You must pull these commits down to stay updated.
git pull Really Doing?git pull is actually a combination of two underlying Git commands:
git fetch: Downloads all commits, branches, and tags from the remote repository into your local .git folder, updating remote-tracking branches (like origin/main), but leaves your working directory untouched.git merge origin/main: Integrates the fetched commits into your active local branch.Or execute both in one command:
If a colleague pushed commits to GitHub while you were working locally, GitHub will reject your push with:
git push --force on shared production branches! Force-pushing overwrites and deletes your teammates' commits from the remote server.git push -u origin main accomplish?git pull?git fetch differ from git pull?(fetch first) non-fast-forward error?git push --force strongly discouraged on shared collaborative branches?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.