Notes about Git: Difference between revisions

From OpenPetra Wiki
Jump to navigation Jump to search
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Manuals ==
* Crash Course: http://git.or.cz/course/svn.html
* Crash Course: http://git.or.cz/course/svn.html
* User Manual for Git: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html
* User Manual for Git: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html
* Very good article about how to work with branches http://nvie.com/git-model
== Issues ==
=== Branches for development of OpenPetra ===
** in my own words: working with branches is central to git; some people make a branch for each feature they are working on; I think each developer should have his own branch (or even several if working on different OS or machines), and merge to master as often as possible; you can have local and remote branches; it would make sense to create a local branch, and then push it to the server creating a remote branch.
** http://sites.google.com/a/insoshi.com/insoshi-guides/Git-Guides/working-on-a-local-development-branch
** http://sites.google.com/a/insoshi.com/insoshi-guides/Git-Guides/pushing-up-your-changes
** http://blog.hasmanythrough.com/2008/12/18/agile-git-and-the-story-branch-pattern
** http://sites.google.com/a/insoshi.com/insoshi-guides/Git-Guides/merge-vs-rebase
# first make sure we are on the main branch
git checkout master
# create a local branch that is called mynewbranch
git branch mynewbranch
# switch to that branch
git checkout mynewbranch
# create the branch also on the remote repository
git push ssh://..../openpetraorg/openpetraorg/ mynewbranch:refs/heads/mynewbranch
# change config so that future git push will go into correct remote branch
git config branch.mynewbranch.remote ssh://..../openpetraorg/openpetraorg
git config branch.mynewbranch.merge refs/heads/mynewbranch
# push changes in local branch to remote branch
git push
# make your changes in the branch, commit to branch
git commit -a
# push branch to remote branch
git push
# switch to master
git checkout master
# get latest from master
git pull
# merge from branch
git merge mynewbranch
# push to master
git push
# switch to branch again
git checkout mynewbranch
todo: get the changes from HEAD into your local branch
=== Branches for adjustments for other organisations ===
benefit: you can make modifications to the UINavigation and the base data structure etc. and even to the screen en.yml files
I have this setup for one organisation:
* created on my own server a git repository with an anonymous clone from the sourceforge openpetraorg git repository.
* cloned my own repository to my workstation
* on the workstation: create a branch on the repository, switch to the branch, modify a file, commit changes locally, push it not to master, but enter the name of your branch
** dangerous: after you have created the branch on the server, NEVER switch to the remote branch: commits to that undefined branch will be eventually be lost at the next switch between branches, and you cannot push from that undefined branch. First create a local branch, and then pull from the remote branch into your local branch!
* on the workstation, on a fresh git pull: git checkout -b branchname origin/BRANCHNAME
* you can pull on your server from the sf repository, to follow the changes in the main repository, and merge from master into your branch
** pull from server: do this on the command line on your server, current branch is master, git pull
** merge from master: on my workstation, pull origin/master, which will automatically merge? otherwise merge from remotes/origin/master; then push to my branch on my server
* you should create patches of your own development and post them in the OpenPetra forum so that all other users can benefit from your improvements
=== line feed issues ===
** see also http://stackoverflow.com/questions/861995/is-it-possible-for-git-merge-to-ignore-line-ending-differences
** see also http://stackoverflow.com/questions/1011985/line-endings-messed-up-in-git-how-to-track-changes-from-another-branch-after-a
** http://git.or.cz/gitwiki/GitSvnComparsion suggests that on Windows in the config file in .git, you should set "core.autocrlf = true so that text files are automatically checked out with CRLF and checked in as LF".
** see also discussion at http://code.google.com/p/msysgit/issues/detail?id=21
=== delete a remote branch ===
* if a remote branch is not needed anymore, and everything has merged into master, we don't want to see the branch anymore
git push ssh://MYUSERNAME@openpetraorg.git.sourceforge.net/gitroot/openpetraorg/openpetraorg :refs/heads/MYBRANCHTODELETE
=== selective merge ===
* see also discussion here:
** http://stackoverflow.com/questions/449541/how-do-you-merge-selective-files-with-git-merge
* http://jasonrudolph.com/blog/2009/02/25/git-tip-how-to-merge-specific-files-from-another-branch/
** git checkout
* http://tech.efreedom.com/Question/1-449541/How-do-you-merge-selective-files-with-git-merge
** git cherry pick http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html
** or splitting one commit into several commits with rebase
* with tortoiseGit: show log, right click on commit, cherry pick
** see also http://code.google.com/p/tortoisegit/issues/detail?id=285


== TortoiseGit ==
== TortoiseGit ==
* http://code.google.com/p/tortoisegit/
For development on Windows, we recommend [[Setup_of_Development_Environment_for_Windows#TortoiseGit|TortoiseGit]]
 
This works fine on Windows, although it is still work in progress...


== Git Bash ==
== Git Bash ==

Latest revision as of 12:45, 9 September 2010

Manuals

Issues

Branches for development of OpenPetra

# first make sure we are on the main branch
git checkout master
# create a local branch that is called mynewbranch
git branch mynewbranch
# switch to that branch
git checkout mynewbranch
# create the branch also on the remote repository
git push ssh://..../openpetraorg/openpetraorg/ mynewbranch:refs/heads/mynewbranch
# change config so that future git push will go into correct remote branch
git config branch.mynewbranch.remote ssh://..../openpetraorg/openpetraorg
git config branch.mynewbranch.merge refs/heads/mynewbranch
# push changes in local branch to remote branch
git push

# make your changes in the branch, commit to branch
git commit -a
# push branch to remote branch
git push
# switch to master
git checkout master
# get latest from master
git pull
# merge from branch
git merge mynewbranch
# push to master
git push
# switch to branch again
git checkout mynewbranch
todo: get the changes from HEAD into your local branch 

Branches for adjustments for other organisations

benefit: you can make modifications to the UINavigation and the base data structure etc. and even to the screen en.yml files

I have this setup for one organisation:

  • created on my own server a git repository with an anonymous clone from the sourceforge openpetraorg git repository.
  • cloned my own repository to my workstation
  • on the workstation: create a branch on the repository, switch to the branch, modify a file, commit changes locally, push it not to master, but enter the name of your branch
    • dangerous: after you have created the branch on the server, NEVER switch to the remote branch: commits to that undefined branch will be eventually be lost at the next switch between branches, and you cannot push from that undefined branch. First create a local branch, and then pull from the remote branch into your local branch!
  • on the workstation, on a fresh git pull: git checkout -b branchname origin/BRANCHNAME
  • you can pull on your server from the sf repository, to follow the changes in the main repository, and merge from master into your branch
    • pull from server: do this on the command line on your server, current branch is master, git pull
    • merge from master: on my workstation, pull origin/master, which will automatically merge? otherwise merge from remotes/origin/master; then push to my branch on my server
  • you should create patches of your own development and post them in the OpenPetra forum so that all other users can benefit from your improvements

line feed issues

delete a remote branch

  • if a remote branch is not needed anymore, and everything has merged into master, we don't want to see the branch anymore
git push ssh://MYUSERNAME@openpetraorg.git.sourceforge.net/gitroot/openpetraorg/openpetraorg :refs/heads/MYBRANCHTODELETE

selective merge


TortoiseGit

For development on Windows, we recommend TortoiseGit

Git Bash

  • You need to add each changed file before you commit. Otherwise that file will not be part of the next commit.
  • If you added too many files by accident, and you want to lose them completely: (use this carefully with -f) git rm . -r
    • even better: to unstage: git reset HEAD <file>...
  • undo all local changes: git checkout -f
  • to revert a single file: use git checkout filename (see http://norbauer.com/notebooks/code/notes/git-revert-reset-a-single-file)
  • to ignore eg. *.bak files, create a file .gitignore and add the files; eg see OpenPetra/csharp/.gitignore