A slightly open question regarding best practices, I can find lots of functional guides for git but not much info about standard ordering of operations etc:

Whats the standard/nice way of working with remote repositories, specifically for making a change and taking it all the way back to the remote master. Can someone provide a step-by-step list of procedures they normally follow when doing this. i.e. something like:

  1. clone repo
  2. create new local branch of head
  3. make changes locally and commit to local branch
  4. ...

closed as primarily opinion-based by bwDraco, DavidPostill, Kevin Panko, random Jan 31 '15 at 16:55

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.


Here is how I do it. I usually work on the remote repository by myself so comments are welcome, especially from people who use a similar workflow collaboratively.

On local computer: clone the remote repository.

git clone ssh://user@master:path/my_rep
cd my_rep

The cloned repository creates automatically an 'origin' link to the master. Before working it is a good idea to pull the latest changes and create a local branch:

git pull origin --rebase
git checkout -b local_mybranch
(... work ...)
git commit -a
(... work ...)
git commit -a

Before pushing your changes to the master you can always do a pull of the master change and rebase your work branch on it. A trick I often use is to make a rebase with the -i option. That way you can paste your commit together in one single giant commit.

git checkout master
git pull --rebase
git checkout local_mychanges
git rebase -i master

Then push your changes on remote: git push origin local_mybranch:mybranch_on_remote

On the remote repository. You (or someone else) can merge the changes in the master branch.

git checkout master    
git merge mybranch_on_remote

Because my projects are normally web applications that I want to develop locally and test on a remote server, I almost always keep up to date copies of all branches on the remote. The only exception would be if I doing a very vague proof-of-concept test.

So, if the repo you're pulling from is called origin and the branch you make locally is called mybranch, my workflow is:

1) Clone the repo from origin

2) Checkout a new branch

3) Push the branch to origin and set it to consider the upstream version with:

git push -u origin/mybranch

This means you keep the canonical version of every branch on the server, which has a couple of advantages.

You can easily see version history on my code hosting site, and you can pull a test branch from the remote onto a staging server to test it out there.

It also means that anyone else working on your project can easily view, check out and track merges to and from that branch.

If you've already pushed your branch to the server but not set it to consider that remote copy its upstream, use this:

git branch --set-upstream-to=origin/mybranch

Not the answer you're looking for? Browse other questions tagged or ask your own question.