Personal tools
You are here: Home / Internal / How To / Git collaboration use cases

Git collaboration use cases

Here you find a number of use cases and how they are realize with git.

Ask a collegue for help

Use case: You work together with a group of people on the master branch. You run into a problem, i.e., your local uncommitted work doesn't compile. You need help from your co-workers.

Committing to the master branch is a no-go since that would interfere with the work of others. Of course you can send over the files via mail to your collegues or (already better) use "git format-patch", "git send-email", and "git am" so that others can reproduce your problem, you can also use branches to do the magic.

Solution: Create a new branch, commit your work to that branch, push it to the server. Then ask your collegue by pointing him/her to that branch. You can then work together to resolve the issue by freely committing to this new branch. At the end use "git rebase -i" to tidy up the commits and move them to the master branch.

git checkout -b NEW-BRANCH-NAME
git add FILE1 FILE2 # all problem relevant files
git commit
# In the commit message you should enter the full error description, including
# compiler log messages etc. etc.
git push origin NEW-BRANCH-NAME

Now work with your collegue on that branch to resolve the issue. You are now on branch NEW-BRANCH-NAME and have committed one or more commits to that branch. Of course, you don't want these intermediate commits to make it into the master branch.

git rebase -i master

Experiment a bit with that command, but it will allow you to edit the commit messages, squash several commits together or even edit one of the commits. After you have "beautified" your commits, you can merge them into master.

git checkout master
git merge NEW-BRANCH-NAME

What is my current branch?

Use case: You work with git on the command line and wonder on which branch you currently are.

It's easy enough to find out via

git branch

Look for the little *.

Solution: You should use bash as your standard shell. Use chsh or ypchsh and set the default shell to /bin/bash. If you are a fan of csh or tcsh, then maybe you should read http://en.wikipedia.org/wiki/C_shell#Criticism, http://www.shlomifish.org/open-source/anti/csh/, http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/, and http://www-uxsup.csx.cam.ac.uk/misc/csh.html.

If you haven't yet installed bash-completion do so.

sudo apt-get install bash-completion git

Then you have to put the following lines into your ~/.bashrc.

source /etc/bash_completion
source /etc/bash_completion.d/git
PS1="\h:\w"'$(__git_ps1 ":%s")'">"
GIT_PS1_SHOWDIRTYSTATE=true # */+ for dirty
GIT_PS1_SHOWSTASHSTATE=true # $ for stashes
GIT_PS1_SHOWUNTRACKEDFILES=true # % for untracked

Now open up a new terminal and cd into a git repository. You will see something like this (maybe not that colorful): http://www.seejohncode.com/2012/05/01/git-bash-completion-and-detail/

Also note that from now on you can press TAB to complete a git command.

Next (yet unwritten) use case

« November 2024 »
November
MoTuWeThFrSaSu
123
45678910
11121314151617
18192021222324
252627282930
Upcoming Events
RISC Forum Dec 02, 2024 01:30 PM - 01:45 PM
RISC Forum Dec 09, 2024 01:30 PM - 01:45 PM
RISC Forum Dec 16, 2024 01:30 PM - 01:45 PM
NO RISC Forum Dec 23, 2024 01:30 PM - 01:45 PM
NO RISC Forum Dec 30, 2024 01:30 PM - 01:45 PM
Previous events…
Upcoming events…