3

I am using gitlab and really confused in few things. :

  1. When we create new branch by git checkout -b test. Does it create copy of master or it creates copy of branch i am currently in?

For example: I am currently at branch dev, then i write command git checkout -b test. So it will be copy of dev, not masters?

  1. Pull : when we write git pull , it pulls changes of current branch from remote branch of same name. Its used when more people are working on same project.

Example : I am at branch dev, i write git pull, it updates my local as of dev in remote. Now i created a new branch test, checkout test branch and do git pull. It gives me :There is no tracking information for the current branch. Please specify which branch you want to rebase against.

its because there is no test branch in remote ? What command to be used if i want to pull from dev branch while my current branch is test? is it git pull --rebase dev test?

  1. When we write git push, it pushes current branch to remote one. example : i am on branch test, i add, commit and write git push. It simply pushes my branch test to remote with same name as test. Can we push to specific branch like push test to dev?

What is difference in following considering i am at branch test: git push git push origin test they both push to remote?

My requirement is : there is branch dev which is not master branch, i am supposed to work on this branch as starting and end point. Like, new branch should be copy of this and i am supposed to push to same branch.

SeleniumTester
  • 331
  • 1
  • 7
  • 17

2 Answers2

9

Does it create copy of master or it creates copy of branch i am currently in?

It creates a new branch named test based on the current branch, whatever that might be, as a starting point.

What command to be used if i want to pull from dev branch while my current branch is test?

I believe you can pull any branch you wish into your current branch. E.g. if you were on branch test and wanted to pull dev you could just use:

git pull origin dev

Can we push to specific branch like push test to dev?

Yes, can specify both the local and remote branch names when pushing, e.g.

git push origin test:dev
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

1- When you do git checkout -b test it creates copy of your current branch(in this case 'dev').

2- git pull will only sync your changes between remote and local. If you upload the branch and try to pull, it does not work because your local and remote changes will be synchronized.

3- This could help you : Make an existing Git branch track a remote branch?.

If you want to work in a copy of a branch, you should do this:

  • git checkout <origin_branch> (master, dev, what u want )
  • git checkout -b <work_branch> (test, for example. This create a copy of your origin branch)

After this, you have a new branch 'test' in your local repository. If you want to push this branch on the repo:

  • git add .
  • git commit -m "Pushing new branch test"
  • git --set-upstream origin <your_new_branch>
Aw3same
  • 930
  • 4
  • 13
  • 38