Git - Remote

Working with Remote Git Repositories

# show origin with URL
git remote -v
# update remote tracking branches
git remote update
# see changes/diffs between upstream work and local work
git log -p ..@{u}
# integrate downloaded changes
git merge @{u}
# or rebase your work with upstream changes
git rebase @{u}
# to speed up the integration of remote work you might use:
git pull origin yourbranch
# this will fetch from origin and merge (ff) your local branch "yourbranch" 
# upload all changes you made the steps before to upstream again
git push
# delete a branch local and remote
git branch delete feature/bugfix
git push origin --delete feature/bugfix
# get rid of stale remote branches - delete local branches referencing remote branches
# which don't exist anymore
git remote prune origin

Mix https and ssh for git remote url

With github for example it is possible to access your repository via https or ssh. Both have their pro and cons.

Cloning the repository over https is easy, you don't need to have your ssh-key loaded. On the other side, if you want to push changes back to your origin (say: github), then it is much more convenient to use the ssh equivalent. With your ssh-key loaded, you don't need to specify your username and password for the push.

So why not mix both together? Use https to pull and ssh to push? This can be done like so:

# first clone via https
git clone
# check your remote:
git remote -v
origin (fetch)
origin (push)
# change the url for the push stanza:
git remote set-url --push origin
# and check again:
git remote -v
origin (fetch)
origin (push)
# perfect!

Creating a Remote Repo from a Local One:

If you were working with your local Git repo and you want to have a central remote repo somewhere else here are the steps to make that happen. Just to be precise: in this example, the “remote” repo will reside in an nfs-mounted directory so we can access it via the file directive.

  1. create a bare Git repo where you want your central “remote” repo
  2. push your local repo to the remote one
  3. make the remote repo the origin of your local repo

The commands to run:

# create the "remote" repo to be:
cd /nfs/vcs/
mkdir example.git
cd example.git
git init --bare
# push your local repo to the new origin:
cd ~/vcs/example
git push --all /nfs/vcs/example.git/
git remote add origin file:///nfs/vcs/example.git
git remote -v
origin  file:///nfs/vcs/example.git (fetch)
origin  file:///nfs/vcs/example.git (push)
# make sure your new remote is set as the default remote:
git branch --set-upstream master origin/master

To use the new remote repo just clone it.

howto/git/git_remote.txt · Last modified: 2017-10 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready