Upload a Local Repo to Remote Linux
This tutorial covers how to set a Fundamental Repo every bit a remote to your local repo in order to update your local fork with updates. You want to do this every time earlier starting new edits in your local repo.
Learning Objectives
At the end of this action, you will be able to:
- Explain why it is of import to update a local repo before beginning edits.
- Update your local repository from a remote (upstream) central repo.
Additional Resources
- Diagram of Git Commands: this diagram includes more commands than we will acquire in this series.
- GitHub Help Learning Git resource
We now take done the following:
- We've forked (made an individual copy of) the
NEONScience/DI-NEON-participantsrepo to our github.com account. - Nosotros've cloned the forked repo - making a copy of it on our local computers.
- Nosotros've added files and content to our local re-create of the repo and committed the changes.
- We've pushed those changes back upwards to our forked repo on github.com.
- We've completed a Pull Request to update the fundamental repository with our changes.
Once you're all setup to work on your project, you lot won't demand to repeat the fork and clone steps. But you practice want to update your local repository with any changes other'south may have added to the central repository. How practice we do this?
Nosotros will do this by direct pulling the updates from the fundamental repo to our local repo past setting up the local repo as a "remote". A "remote" repo is any repo which is non the repo that you lot are currently working in.
LEFT: You will fork and clone a repo only one time . RIGHT: After that, y'all will update your fork from the central repository past setting information technology upwards as a remote and pulling from it with git pull . Source: National Ecological Observatory Network (NEON)
Update, so Work
One time you've established working in your repo, you should follow these steps when starting to work each time in the repo:
- Update your local repo from the key repo (
git pull upstream master). - Make edits, save,
git add together, andgit commitall in your local repo. - Push changes from local repo to your fork on github.com (
git button origin primary) - Update the primal repo from your fork (
Pull Asking) - Repeat.
Find that we've already learned how to do steps 2-4, now we are completing the circle by learning to update our local repo directly with any changes from the central repo.
The order of steps higher up is important as it ensures that you incorporate any changes that have been made to the NEON central repository into your forked & local repos prior to calculation changes to the central repo. If you practise not sync in this order, y'all are at greater take chances of creating a merge conflict.
What's A Merge Conflict?
A merge conflict occurs when two users edit the same role of a file at the aforementioned time. Git cannot determine which edit was first and which was last, and therefore which edit should exist in the most current re-create. Hence the conflict.
Merge conflicts occur when the aforementioned office of a script or document has been changed simultaneously and Git can't determine which change should be applied. Source: Atlassian
Fix up Upstream Remote
We want to directly update our local repo with any changes made in the central repo prior to starting our next edits or additions. To do this we need to prepare upwardly the central repository as an upstream remote for our repo.
Pace 1: Become Central Repository URL
First, we need the URL of the central repository. Navigate to the central repository in GitHub NEONScience/DI-NEON-participants. Select the green Clone or Download push button (just similar we did when we cloned the repo) to re-create the URL of the repo.
Step ii: Add the Remote
Second, nosotros demand to connect the upstream remote -- the central repository to our local repo.
Brand sure yous are still in you local repository in bash
Kickoff, navigate to the desired directory.
$ cd ~/Documents/GitHub/DI-NEON-participants and and then type:
$ git remote add upstream https://github.com/NEONScience/DI-NEON-participants.git Here you are identifying that is is a git control with git and so that you are calculation an upstream remote with the given URL.
Step three: Update Local Repo
Utilize git pull to sync your local repo with the forked GitHub.com repo.
Second, update local repo using git pull with the added directions of upstream indicating the cardinal repository and master specifying which branch you are pulling down (call back, branches are a keen tool to look into once yous're comfy with Git and GitHub, just we aren't going to focus on them. Just utilise master).
$ git pull upstream master remote: Counting objects: 25, done. remote: Compressing objects: 100% (fifteen/15), washed. remote: Total 25 (delta 16), reused nineteen (delta x), pack-reused 0 Unpacking objects: 100% (25/25), done. From https://github.com/NEONScience/DI-NEON-participants 74d9b7b..463e6f0 principal -> origin/master Car-merging _posts/institute-materials/instance.dr. Understand the output: The output volition change with every update, several things to look for in the output:
-
remote: …: tells you how many items have changed. -
From https:URL: which remote repository is information being pulled from. We set up the central repository equally the remote but it can be lots of other repos also. - Section with + and - : this visually shows you lot which documents are updated and the types of edits (additions/deletions) that were fabricated.
Now that you've synced your local repo, let'south cheque the status of the repo.
$ git status Step four: Complete the Cycle
At present you lot are set upwardly with the additions, you will need to add and commit those changes. In one case you've done that, you lot can push the changes dorsum upwards to your fork on github.com.
$ git push origin main Now your commits are added to your forked repo on github.com and you're prepare to repeat the loop with a Pull Request.
Workflow Summary
Syncing Central Repo with Local Repo
Setting It Up (just exercise this the initial fourth dimension)
- Find & copy Key Repo URL
-
git remote add upstream https://github.com/NEONScience/DI-NEON-participants.git
Subsequently Initial Set
-
Update your Local Repo & Push Changes
-
git pull upstream master- pull down any changes and sync the local repo with the cardinal repo - make changes,
git addandgit commit -
git push origin master- push button your changes upwards to your fork - Repeat
Have questions? No problem. Leave your question in the comment box below. Information technology's likely some of your colleagues accept the aforementioned question, too! And too probable someone else knows the answer.
-
Source: https://www.neonscience.org/resources/learning-hub/tutorials/git-setup-remote
0 Response to "Upload a Local Repo to Remote Linux"
Post a Comment