Working with Git on a day-to-day basis with two different computers

Asked

Viewed 2,431 times

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.

2 answers

8


You’ve made yourself complicated from this point:

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...

All you have to do is continue the development, just updating your local branch:

git ckeckout dev;
git pull;

Then do the push for origin and continue this cycle, pull -> commit -> push

Meanwhile, recommend a more advanced flow with the use of topical branchs as you will find exemplified in the chapter Branching Workflows and the use of hack and ship but this you leave further ahead in your studies :)

Branching Workflows

Image source: git-scm.com

  • 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?

  • @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)

  • If at pull time git says it doesn’t know which branch to grab, use git pull origin dev. @rodrigoum

  • @gpupo thank you so much for the information. How nice to have a history of everything I did :D

0

I would suggest using the git flow structure. You would have the master branch that is exclusive to deploy Branch develop to receive Features as each new feature finishes So both at home and at work you would give a Publish in the functionalities to be able to work in both places in a more organized way.

I suggest you see: https://danielkummer.github.io/git-flow-cheatsheet/index.pt_BR.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.