Peter Kam
Peter Kam

Reputation: 103

Git pull origin [branch name] vs git checkout -t origin/[branch name]

I do jobs in local server and push them to the branch. after that, I would like to pull the branch from remote repository to webserver. When I would like to bring the jobs updated on the branch into the web server, which command on the following is correct?

git pull origin [branch name]

vs.

git checkout -t origin/[branch name]

The job I've done on branch is now totally different with the main one. I do not want any merge branch to main so now the job on branch is like other project, nothing to do with the original project on the main. let me call the jobs I've done on the branch 'B project'. I would like to manage B project only on the branch and original one still on main.

Is that a good idea? Or is there a better way for this plan?

Upvotes: 0

Views: 295

Answers (2)

ale917k
ale917k

Reputation: 1768

For my understanding, you have a main project and a different project which is based on the main, while being significantly different.

If that's the case, I would have different repositories for the two, so to keep them more maintainable.

The main repo will stay as it is, while on the second one we want to add the main repo as a remote origin.

To do that let's first:

  1. Create a new repo at github
  2. Clone the main repo locally if not done already

You can then add the main repo as a remote origin:

  1. git remote rename origin upstream
  2. git remote add origin URL_TO_MAIN_GITHUB_REPO
  3. git push origin master

Now you can work with it just like any other github repo.

To pull in patches from upstream, simply run git pull upstream master && git push origin master.

To underline I would follow this solution if you have two different projects based on some common changes, as branches works well for features / patches you would then want to merge to master once they are completed.

If, on the other hand, you simply have the same project with different features, then @Deniz da King solution is great.

Upvotes: 1

Deniz da King
Deniz da King

Reputation: 401

You could use separate branches for each feature. I personally use a hierarchy similar to below.

/
|---features
    |--- A
    |--- B

That would result in /features/A and /features/B branches respectively. That way you could work on your features on separate branches and use main branch as stable version of your application.

After your last edit, I would definitely recommend the solution below.

Or a better solution for entirely different jobs, you could use git-worktree command.

git worktree add [-b <new-branch>] <path> [<the branch/tree you want to base this worktree>]

This is the best I could from what I've understand from your question.

Upvotes: 1

Related Questions