Comments (6)
git pull upstream main
Pulls (downloads) the changes on the main branch of this repository to your local computer. Have you previously pulled from upstream main and made changes to it on your local computer?
from coding-interview-university.
Thanks a lot for the reply. 👍
I have followed the instructions from the git section at https://github.com/jwasham/coding-interview-university#how-to-use-it.
I have done the following steps:
- Fork the repo to my own github repo.
Then:
git clone https://github.com/<YOUR_GITHUB_USERNAME>/coding-interview-university.git
cd coding-interview-university
git remote add upstream https://github.com/jwasham/coding-interview-university.git
git remote set-url --push upstream DISABLE # so that you don't push your personal progress back to the original repo
But I haven't done these steps below yet, because I am worried that doing "git pull upstream main" will overwrite any changes I have made locally (that is, when I start checking checkboxes as I work through the README).
git commit -am "Marked personal progress"
git pull upstream main # keep your fork up-to-date with changes from the original repo
It may be that I am just misunderstanding how it works, but I just want to be sure before I begin. My current understanding is that git commit
will upload my changes to my GitHub repo, but git pull
will overwrite the changes on my local cloned copy...
Thanks for any further explanation anyone can provide.
from coding-interview-university.
@scop22 As I understand it, it wouldn't automatically overwrite changes, it's most likely going to attempt to pull changes down, then create a merge conflict warning
from coding-interview-university.
@scop22 As I understand it, it wouldn't automatically overwrite changes, it's most likely going to attempt to pull changes down, then create a merge conflict warning
You are right
from coding-interview-university.
Hi there,
If anyone has a way to make this process better, please update the documentation and create a pull request.
I appreciate it.
from coding-interview-university.
This is going to be a long reply that warrants a tldr.
TLDR; No. It will either succeed or wouldn't if you have any changes made. Regarding the latter, you'll be asked to do any of the following; commit, stash or resolve conflicts (if any).
Long answer:
In order to keep things brief as much as possible, know that this answer may not be entirely accurate because it does not cover the nuances with regards to the following concepts; branches, fast-forward merge, working area, staging and stashing. Now, lets explain the commands as briefly as possible.
First set of commands
- Fork the repo to my own github repo
Creates a copy of the original repo to your Github repos (referencing the original). The repo is on Github servers not your local computer.
git clone https://github.com/<YOUR_GITHUB_USERNAME>/coding-interview-university.git
Downloads a the repo you forked onto you local computer. In doing so, a new folder/directory is created from the location where you ran the command with the repo's name; in this case coding-interview-university
cd coding-interview-university
Navigate to the folder (repo) that was just created on local computer. To work on the files in the repo you need to access it's content and that's all this step is enabling us to do.
At this point, you can modify the files in the repo on your local PC and save (Ctrl+S or Cmd+S) them. However, saving the files and committing them mean different things when it comes to git repos. To oversimplify, think of it like this; the former saves the changes but those changes cannot be recovered if the files get overwritten or corrupted while the latter saves the changes permanently (kind of-only on your local PC) and can be recovered if any of the files get overwritten or corrupted. So most of the time you'll be saving and committing once you're done with your changes. But it is only local to your PC. To save it to the cloud (Github in this case), you need to upload (push) your commits to your repo stored on Github. Which can be done with
git push origin
or simply git push
Why does it work? It is because a reference is made to your github repo when you cloned it to your local PC and you can view all possible online (remote) repos that you can upload (push) and download (pull) changes from with the command:
git remote -v
Likely output:
origin https://github.com/<YOUR_GITHUB_USERNAME>/coding-interview-university.git (fetch)
origin https://github.com/<YOUR_GITHUB_USERNAME>/coding-interview-university.git (push)
By default you'll have only one which would be named origin so during git push origin
and git pull origin
specifies the remote repo to apply those actions. When the remote repo is not specified the default is origin.
So now that you hopefully understand the concept of git remotes what about
git remote add upstream https://github.com/jwasham/coding-interview-university.git
Seems self-explanatory enough. We're adding another remote (online repo source) named upstream to our local repo. In this case, it is the original Github repo by @jwasham which was forked (i.e this repo). Runing git remote -v
again outputs
origin https://github.com/<YOUR_GITHUB_USERNAME>/coding-interview-university.git (fetch)
origin https://github.com/<YOUR_GITHUB_USERNAME>/coding-interview-university.git (push)
upstream https://github.com/jwasham/coding-interview-university.git (fetch)
upstream https://github.com/jwasham/coding-interview-university.git (push)
You'll notice there are two urls for each remote; one labelled fetch (for downloading) and another labelled push (for uploading). This means we can push to both our personal copy of the repo on Github (origin) and the original by @jwasham (upstream -- technically not possible unless you know his account credentials). Nevertheless, to remove the possibility of trying to push to the @jwasham's repo we run the command.
git remote set-url --push upstream DISABLE
# so that you don't push your personal progress back to the original repo (everything after the # symbol is not part of the command)
The command above just replaces the url for the upstream push url to the literal text DISABLE which is not a valid url and thus pushing to upstream will fail. Now again running git remote -v
we get
origin https://github.com/<YOUR_GITHUB_USERNAME>/coding-interview-university.git (fetch)
origin https://github.com/<YOUR_GITHUB_USERNAME>/coding-interview-university.git (push)
upstream https://github.com/jwasham/coding-interview-university.git (fetch)
upstream DISABLE (push)
Second set of commands
git commit -am "Marked personal progress"
git pull upstream main` # keep your fork up-to-date with changes from the original repo
After modifying and saving the files, running
git commit -am "Marked personal progress"
commits the changes to your local repo with message "Marked personal progress". Every commit requires a commit message usually to summarise what modifications have been made. It can be empty though.
Typically, you'd also want to apply the changes to your remote repo (as backup). So you must push to origin using
git push origin
Now, these commands should be enough and most of your needs. However, this repo is updated by @jwasham from time-to-time. So to obtain those changes you run the command
git pull upstream main
# keep your fork up-to-date with changes from the original repo
This pulls the changes made to this repo to your local repo (on your PC) and after that you can use git push origin
to update your forked repo (on Github).
NB: You'd mostly want to pull from upstream after you've committed and pushed to origin. This is to ensure that in the case where you mess up your local repo when there is a conflict you'd still have your modifications in your forked repo. Therefore, you can decide to delete your messed up local repo and re-clone your forked repo.
PS: It would really help you to get a high overview of how version control with git and github works. A short article or video will do.
from coding-interview-university.
Related Issues (20)
- Link checker report HOT 1
- Starting to code learning plan
- Study guide HOT 5
- Start HOT 1
- CS
- I Would Like To Request Listing my New Tool To Your Github Projects HOT 1
- Начать программировать HOT 2
- T
- Wrong link to c book answers HOT 1
- Interview university
- R
- Translation: Burmese HOT 3
- Bbhhh
- Check
- Hi HOT 1
- 🦚
- Coding interviews HOT 1
- Interview perp
- .
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coding-interview-university.