Skip to content

Instantly share code, notes, and snippets.

@havvg
Created March 15, 2012 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havvg/2046776 to your computer and use it in GitHub Desktop.
Save havvg/2046776 to your computer and use it in GitHub Desktop.
git up
[alias]
up = !git merge --ff-only upstream/`git branch --no-color | grep -e '^\\*' | cut -d\" \" -f2`
@cordoval
Copy link

please could you explain? i am watching you :D

thanks

@cordoval
Copy link

this should not work

~ git branch --list
error: unknown option `list'

@havvg
Copy link
Author

havvg commented Mar 16, 2012

 ~ git --version ~
git version 1.7.9.2

Maybe you got an older version of git, where the --list option is not available. You can omit it then.

What this command line expects:

  • You got a remote called upstream.
  • This remote contains a branch with the same name as your current local branch.
  • A fast-forward merge of this remote branch will be applied to the current local branch.

Example:

  • Fork any github repository.
  • Add your fork as remote origin.
  • Add the forked repository as remote upstream.

This is in fact a very common pattern and may be considered "Best Practice".

@cordoval
Copy link

cordoval: Use git branch --set-upstream and 'git pull' like normal people? he was not right
I finally upgraded to the latest and solved this problem

http://www.craftitonline.com/2012/03/updating-git-to-the-latest-on-ubuntu/

@havvg
Copy link
Author

havvg commented Mar 17, 2012

It's not about pull from the tracking branch, which would be altered by --set-upstream as you mentioned.
It's about having two different remote repositories to merge from.

Like I said, you have your like "central" (Yes, I know git is not centralized.) remote, where your company pushes to and pulls from (called origin). A clean push and pull will interact with that remote and their respective branches. You would track new branches from there - git co -b feature/new-feature --track origin/feature/new-feature which allows simple git push and git pull.

In addition you have the official remote repository called upstream. No one of your company is allowed to push to it, you only update from it. This is what git up does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment