jjLin
jjLin

Reputation: 3291

Git how to work on a branch with local and remote

I have a project in remote server.
1)At home, I clone the project and then edit something in master and then push to remote.(What is the command?)
2)At company, I clone the project(before step1), now, i want to continue my task, so I want to update from remote. (What is the command?)
3)Then, after update, I create a new branch and work on new features, but not enough time, so I want to push to remote and continue my work at home. (What is the command?)
4)When I back home, I want to update my existing project from remote and continue my task. (What is the command?) And then I edit something and want to push to remote and continue my work at company. (What is the command?)
5)Then, I go back to company next day, I want to update from remote and continue my task.(What is the command?)
6)Finally, I have another computer A, I want to clone from remote and work on the branch.(What is the command?). After edit something, I want to push to remote. (What is the command?)

I am really a starter of git.
Step 4 ,5 and step 6 is the most difficult part as I don't know how to continue to work on a branch or clone project from remote and then work on the branch.
Please help me.

Upvotes: 1

Views: 1801

Answers (2)

SzG
SzG

Reputation: 12609

Let's assume you use GitHub for hosting, you're called foo and your project's called bar.

Case 1. Clone and work at home

git clone [email protected]:foo/bar.git
cd bar
... edit
git commit -a
git push origin master

Case 2. At work

git fetch
git merge origin/master

Case 3. New branch at work

git checkout -b feature-1
... edit
git commit
git push origin feature-1

Case 4. Home, continue working on feature-1

git fetch
git checkout -t origin/feature-1
... edit
git commit
git push origin feature-1

Case 5. Work, continue working on feature-1

git fetch
git merge origin/feature-1
... continue

Case 6. Computer A

git clone [email protected]:foo/bar.git
cd bar
git checkout -t origin/feture-1
... edit
git commit
git push origin feature-1

I hope you get the idea. A few tricks:

  • git checkout -b XXX creates a new branch XXX and checks it out in one step
  • git checkout -t YYY/XXX creates and checks out a local branch XXX which tracks branch XXX in remote YYY.

Also make sure you learn the details for each command from the documentation. In other words don't follow my examples blindly.

Upvotes: 4

gtrig
gtrig

Reputation: 12958

First, I would highly recommend this reference:

http://git-scm.com/documentation

There are a number of ways to clone. Look at the chapter titled "Distributed Git". One way is like this:

git clone john@githost:simplegit.git

Assuming remote is named "origin"...

  1. (after cloning); (do work); git push origin master
  2. (after cloning); git pull; (do work); git push origin master
  3. git checkout -b new_branch; (do work); git push origin new_branch
  4. git pull; git checkout new_branch; (do work); git push origin new_branch
  5. git pull; git checkout new_branch (may not be necessary if you're already on that branch); (do work); git push origin new__branch
  6. (after cloning); git pull; git checkout new_branch; (do work); git push origin new_branch

Upvotes: 2

Related Questions