Home > OS >  Working on new feature , git clone or pull?
Working on new feature , git clone or pull?

Time:03-30

Lets say I clone a repository from remote, on my local I created new branch made changed and pushed this branch to remote where master and new branch is merged.

The next time when I need to work on new feature do I need to clone or pull the remote repository ? or git fetch

Whenever I start work on new feature do I have to get the latest copy of master branch ?

CodePudding user response:

You only need to clone the remote repository once. After that, a git pull will always retrieve the latest changes from the remote repository for the branch you're currently on.

So if you want to develop the next feature, you could simply checkout your master branch, git pull it and you're up to date. Then you can create a new branch and start working.

CodePudding user response:

Git clone is required for only the first time to get copy of the repository to local.

You can create new feature branch from master to work on it. Once done, you can push and merge changes to master (Even delete the feature once you are done)

To avoid conflicts while creating new branches, it is best practice to git pull from master, create a feature branch and then make changes to your local repository. In case you have any local changes already, you can choose to git stash them and switch to new branch (and unstash your changes in new branch)

CodePudding user response:

Here are the steps which you can follow

  1. Git Clone (When you first start)
  2. Create a branch from Master
  3. Git Pull (this is important)
  4. Merge with master (or use Pull request)

Step 3 is important, You need to Pull before merge and before you actually create your branch from master.

CodePudding user response:

You will only ever work on feature branches locally. (Merging happens on the server.) So what you want is a simple fetch.

Here's how to work.

  • Never make a local master branch. If you have one now, left over from the clone, delete it.

  • To update your repo from the remote, say git fetch --prune.

  • To start a new feature branch, say git switch -c myFeature origin/master.

That's all. Never say pull. No need to clone again. No conflicts in your repo.

  • Related