10
I have two workplaces where I work on a project where I use GIT version control. In my studies I’ve learned a few things about GIT using Bitbucket.
Let’s think about the following scenario:
- My branch to deploy is the "master".
- Whenever I will develop I will be in a branch "dev".
- Computer Casa.
- Office computer.
I am working from home on a first improvement and for this I create for the first time the branch "dev".
git branch dev
git checkout dev
Okay, I made the improvements, I made the commits in the dev branch and now I’m going to send everything to the Bucket bit (remembering that I’m in the dev branch)
git push origin dev
I sent my changes to Bit Bucket and now I have to go to the office to work from there.
Arriving at the office I clone my repository and at first it will be empty as I will be there in the master branch. Then I give the command to see all the branches
git branch -a
and I have as a result
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/dev
Then create a branch on the office computer based on the remote dev branch
git checkout -b dev origin/dev
I make changes to my project from the office computer, commit to these improvements, and send the server to the dev branch
git push origin dev
Now I’m coming home and will continue to work on the project. So I give the git pull command to download the latest changes. Only I already have on the home computer the dev branch. So I do the following:
git ckeckout -b dev_escritorio origin/dev
Ok, now I have the version in this branch (dev_office) with the improvements I made there. Only I want to continue the improvements by my dev branch so I would:
git checkout dev
git merge dev_escritorio
Well that’s it, I was wondering if this is really the best way when you have to work with two different computers using git, branch, etc.
So if I give a git pull when my current branch is "dev" it would only download the changes to that branch from the repository?
– rodrigoum
@gourodrim exactly. However, I advise the study of the use of topical branchs, and a more advanced flow (I will complement my answer by talking about this flow)
– gpupo
If at pull time git says it doesn’t know which branch to grab, use
git pull origin dev
. @rodrigoum– bfavaretto
@gpupo thank you so much for the information. How nice to have a history of everything I did :D
– rodrigoum