TubeTK/Development/GITCheatSheet: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
Line 1: Line 1:
= Workflow recommendation =
= Workspace tips =
* Show branch in prompt
 
= Maintain a linear git history =
 
== Helpful scripts ==
* http://www.dinnermint.org/tutorial/dead-simple-git-workflow-for-agile-teams
 
== Workflow recommendation ==
# Keep a local master branch which only is a pointer to the gitorious master (does not contain local changes)
# Keep a local master branch which only is a pointer to the gitorious master (does not contain local changes)
# Make development modification in a local branch
# Make development modification in a local branch
Line 19: Line 27:
# If you want to keep a record that your local development was made in parallel to some other development, do a git merge instead of git rebase in step 2 of above
# If you want to keep a record that your local development was made in parallel to some other development, do a git merge instead of git rebase in step 2 of above


= Create a checkout =
=== Create a checkout ===
* git clone git://gitorious.org/tubetk/tubetk.git
* git clone git://gitorious.org/tubetk/tubetk.git




= Stash local changes temporarily =
=== Stash local changes temporarily ===
* git stash
* git stash


= Create a local branch =
=== Create a local branch ===
* git branch test
* git branch test


= Swtich to a local branch =
=== Swtich to a local branch ===
* git checkout test
* git checkout test


= Get stashed local changes =
=== Get stashed local changes ===
* git stash pop
* git stash pop


= Update a branch to the remote master's head =
=== Update a branch to the remote master's head ===
* git stash
* git stash
* git rebase origin master
* git rebase origin master
* git stash pop
* git stash pop


= Add to local commit =
=== Add to local commit ===
* git add <filename>
* git add <filename>
* git add -A
* git add -A


= Push local commit =
=== Push local commit ===
* git push origin master
* git push origin master


= Remove a local branch =
=== Remove a local branch ===
* git checkout master
* git checkout master
* git branch -d <branch>
* git branch -d <branch>


= Track a remote branch =
=== Track a remote branch ===
* "git fetch" (get up to date) or "git pull"
* "git fetch" (get up to date) or "git pull"
* git branch --track somebranch origin/somebranch  
* git branch --track somebranch origin/somebranch  
Line 60: Line 68:
** sends changes to origin/somebranch
** sends changes to origin/somebranch


= Delete a remote branch =
=== Delete a remote branch ===
* Don't do this unless you're incredibly confident in what you're doing
* Don't do this unless you're incredibly confident in what you're doing
* git push origin :somebranch
* git push origin :somebranch


= Project History =
=== Project History ===
* git log        ( To view the history of your changes )
* git log        ( To view the history of your changes )
* git log -p    ( To see complete diffs at each step )
* git log -p    ( To see complete diffs at each step )
* git log --stat --summary  ( To see overview  )
* git log --stat --summary  ( To see overview  )


= Three ways to commit to remote/master =
=== Setting up tracked repositories to start pushing ===
# Without branching    ( Good for quick changes )
# Branching and merging 
# Branching and rebasing
= Additional References =
* GIT tutorial [http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html]
* GIT guide from gitorious [http://qt.gitorious.org/qt-jambi/pages/GitGuide]
* GIT guide in CMake [http://www.cmake.org/Wiki/CMake/Git]
 
= Setting up tracked repositories to start pushing =
#If you have cloned read-only version, do the following first  
#If you have cloned read-only version, do the following first  
## git remote rm origin
## git remote rm origin
Line 87: Line 86:


git://gitorious.org/tubetk/tubetk.git
git://gitorious.org/tubetk/tubetk.git
=== Three ways to commit to remote/master ===
# Without branching    ( Good for quick changes )
# Branching and merging 
# Branching and rebasing
= Additional References =
* GIT tutorial [http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html]
* GIT guide from gitorious [http://qt.gitorious.org/qt-jambi/pages/GitGuide]
* GIT guide in CMake [http://www.cmake.org/Wiki/CMake/Git]

Revision as of 13:55, 22 March 2010

Workspace tips

  • Show branch in prompt

Maintain a linear git history

Helpful scripts

Workflow recommendation

  1. Keep a local master branch which only is a pointer to the gitorious master (does not contain local changes)
  2. Make development modification in a local branch
  3. When getting ready to push these changes to the origin try the following
    1. Do a git pull on master to fetch and merge all changes from gitorious
      1. git checkout master
      2. git pull origin master
    2. Do a git rebase of the topic branch onto master - That is with topic checkout do "git rebase master"
      1. git rebase master topic
    3. Fix any conflicts that result
      1. Edit files
      2. git add -u
      3. git rebase --continue
    4. Merge the topic branch - This will result in an fast-forward merge.
      1. git merge topic
    5. git push your local master branch
      1. git push origin master
  4. If for some reason you have ever pushed your development branch to someone else don't rebase it as this is effectively rewriting history
  5. If you want to keep a record that your local development was made in parallel to some other development, do a git merge instead of git rebase in step 2 of above

Create a checkout


Stash local changes temporarily

  • git stash

Create a local branch

  • git branch test

Swtich to a local branch

  • git checkout test

Get stashed local changes

  • git stash pop

Update a branch to the remote master's head

  • git stash
  • git rebase origin master
  • git stash pop

Add to local commit

  • git add <filename>
  • git add -A

Push local commit

  • git push origin master

Remove a local branch

  • git checkout master
  • git branch -d <branch>

Track a remote branch

  • "git fetch" (get up to date) or "git pull"
  • git branch --track somebranch origin/somebranch
    • --track is not needed unless you've set branch.autosetupmerge to false in your config
  • git checkout somebranch
  • git commit
  • git push
    • sends changes to origin/somebranch

Delete a remote branch

  • Don't do this unless you're incredibly confident in what you're doing
  • git push origin :somebranch

Project History

  • git log ( To view the history of your changes )
  • git log -p ( To see complete diffs at each step )
  • git log --stat --summary ( To see overview )

Setting up tracked repositories to start pushing

  1. If you have cloned read-only version, do the following first
    1. git remote rm origin
  2. Add the proper remote
    1. git remote add origin git@gitorious.org:tubetk/tubetk.git
  3. You can push your changes
    1. git push origin master

git://gitorious.org/tubetk/tubetk.git

Three ways to commit to remote/master

  1. Without branching ( Good for quick changes )
  2. Branching and merging
  3. Branching and rebasing

Additional References

  • GIT tutorial [1]
  • GIT guide from gitorious [2]
  • GIT guide in CMake [3]