0

I'm new to version control software, specifically git, and I have a couple questions regarding local and remote repositories. I've gone through a few tutorials and I understand the basics, but there are a few topics I can't seem to find answers on. These aren't in any particular order of importance, using using numbers for easier reference when answering.

  1. Suppose I have a repository on github and somone sends me a pull request which I merge. What's the standard way that I should update my local repository on my laptop to reflect this? Just clone it again?

  2. I suppose this ties into the first question, but if I'm helping out on a large or very active remote repository, how do I keep my local repository up to date? What if since the last time I cloned there are 10 more commits? Is that something to consider, or is there a fundamental misunderstanding of git on my part?

  3. Not exactly related to the first two, but for professionals in an "office" environment, how does code base management typically work? Is there someone in charge of a repository just like if you were to fork a repository on github and then clone it to your local machine?

Zha
  • 1
  • 1
  • 3
  • 2
    You should review a good Git tutorial. Your question is too broad IMO, asking several fairly large questions. – Tim Biegeleisen Feb 16 '18 at 06:39
  • @TimBiegeleisen do you have any tutorial suggestions? – Zha Feb 16 '18 at 06:42
  • 1
    You could start with the [official Git tutorial](https://git-scm.com/docs/gittutorial). We are happy to help you with a more focused question. – Tim Biegeleisen Feb 16 '18 at 06:43
  • 1. You need to clone remote repository (origin) only one time 2. you can keep it up to date only pulling branch `git pull origin BRANCH_NAME` 3. It depends on office. – Taron Saribekyan Feb 16 '18 at 06:44
  • Possible duplicate of [Updating a local repository with changes from a Github repository](https://stackoverflow.com/questions/1443210/updating-a-local-repository-with-changes-from-a-github-repository) – phd Feb 16 '18 at 13:30
  • @Zha Have you get the answer which helps you solve your questions? If yes, you can mark the answer (√ symbol on the left of the answer). And it will also benefit others who have similar questions. – Marina Liu Feb 23 '18 at 06:14

2 Answers2

0
  1. you should complete the pull request locally and push up the merged branch. This will automatically keep your local and remote instances synchronized.

  2. Use git pull origin [branch], this will pull all of the latest commits from remote branch to your local repository. Use git fetch --all to grab all branches (new created branches as well) from origin repository.

  3. This varies from organization to organization and depends on the underlying business requirements.

Taron Saribekyan
  • 1,360
  • 7
  • 13
Anthony L
  • 2,159
  • 13
  • 25
  • Thanks for the clarification. The only one I'm still a bit confused on is #2. If it's not my repository and I'm only contributing to it, you're saying I should use `git fetch -all` to grab the latest changes rather than just re-cloning it? I suppose that would work for #1 as well, right? – Zha Feb 16 '18 at 06:46
  • You would never re-clone. If you're working on a specific branch and you want to pull down the latest changes and merge them into your local version, you'd use git pull. If you want to grab all of the new branches on the repository, so you can check them out locally, you'd use git fetch. Here's a good primer on the difference: https://www.git-tower.com/learn/git/faq/difference-between-git-fetch-git-pull – Anthony L Feb 16 '18 at 06:53
0

The answer to the questions asked will not be specific as things can be done in numerous ways here. However, I'd like to put forward my opinion based on my knowledge.

  1. Changes in your repo doesn't mean they'll get reflected automatically to your local code base. A git fetch or a git pull is definitely necessary here.
  2. Well its always a good practice to keep your code up to date and implement CI/CD techniques. So in that case, we can always git checkout and git pull the latest changes before starting progress on anything.
  3. Normally, users of a remote repo will have different access rights. So, in a broader sense, only a group of people with Admin privilege are allowed to merge on the delivery branch. A delivery branch is something that actually makes way to production. However, others except for the Admins are free to do permitted things in their respective branches.
Pragun
  • 1,123
  • 8
  • 20