git-tutorial
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
git-tutorial [2012/11/02 11:28] – Enphasized rebasing before sending patch bp | git-tutorial [2017/10/31 17:21] – oofem git repo updated to github bp | ||
---|---|---|---|
Line 18: | Line 18: | ||
git config --global user.email " | git config --global user.email " | ||
- | ====== Git Basics ====== | + | ====== Git Basics |
Our two main branches are: | Our two main branches are: | ||
master | master | ||
- | | + | |
- | The master branch is stable | + | The master branch is used to our development, |
==== Local and remote repositories ==== | ==== Local and remote repositories ==== | ||
Line 40: | Line 40: | ||
If you want to get a copy of an existing Git repository — for example, a project you’d like to contribute to — the command you need is git clone. | If you want to get a copy of an existing Git repository — for example, a project you’d like to contribute to — the command you need is git clone. | ||
- | $ git clone http://www.oofem.org/git/ | + | $ git clone https://github.com/oofem/ |
==== Staging Modified Files ==== | ==== Staging Modified Files ==== | ||
- | If you modify a file and you want to persist this change in the repository you need to perform two steps. First you need to mark them to be relevant for Git. Afterwards you add this change to the Git repository. | + | If you modify a file and you want to persist this change in the repository you need to perform two steps. First you need to mark them to be relevant for Git. Afterwards you add this change to the Git repository. |
Marking changes as relevant for the version control is called staging or to add them to the index. Adding the changes to the repository is called committing. | Marking changes as relevant for the version control is called staging or to add them to the index. Adding the changes to the repository is called committing. | ||
Line 56: | Line 56: | ||
git commit -m "your commit message" | git commit -m "your commit message" | ||
+ | | ||
+ | The commit does not go to a remote server (oofem.org) - this is the major difference with svn. | ||
==== Viewing Your Staged and Unstaged Changes ==== | ==== Viewing Your Staged and Unstaged Changes ==== | ||
Line 72: | Line 74: | ||
# | # | ||
- | ==== Committing Your Changes ==== | + | ==== Committing Your Changes |
- | When the staging area is set up, you can commit your changes. Please note, that anything that is still unstaged — any files you have created or modified won’t go into this commit. They will stay as modified files on your disk. The simplest way to commit is to type git commit: | + | When the staging area is set up, you can commit your changes |
$ git commit | $ git commit | ||
Line 83: | Line 85: | ||
==== Viewing the Commit History ==== | ==== Viewing the Commit History ==== | ||
- | You can show the history of commits in the current branch using gil log command | + | You can show the history of commits in the current branch using git log command |
git log | git log | ||
Line 100: | Line 102: | ||
To track remote branch, for example the develop branch on origin, use | To track remote branch, for example the develop branch on origin, use | ||
- | $ git checkout -b develop | + | $ git checkout -b stable |
If you have Git version 1.6.2 or later, you can also use the --track shorthand: | If you have Git version 1.6.2 or later, you can also use the --track shorthand: | ||
- | $ git checkout --track origin/develop | + | $ git checkout --track origin/stable |
You can switch between branches using git checkout < | You can switch between branches using git checkout < | ||
- | $ git checkout | + | $ git checkout |
- | If you now call git branch, you will see that a new branch named newfeature | + | If you now call git branch, you will see that a new branch named stable |
$ git branch | $ git branch | ||
master | master | ||
- | * develop | + | * stable |
| | ||
To synchronize your work, you run | To synchronize your work, you run | ||
- | $ git fetch origin | + | $ git pull origin |
- | This command looks up which server origin is, fetches any data from it that you don’t yet have, and updates your local database, moving your origin/ | + | This command looks up which server origin is, fetches any data from it that you don’t yet have, and updates your local database, moving your origin/ |
- | ====== Contributing to OOFEM ====== | + | ====== Contributing to OOFEM - Practical workflow |
- | Contributing to oofem project is different. Typically, you don’t have the permissions to directly update branches on the project reference repository and you have to pass your contribution(s) to the maintainers in some way. In OOFEM, | + | Contributing to oofem project is different. Typically, you don’t have the permissions to directly update branches on the project reference repository and you have to pass your contribution(s) to the maintainers in some way. In OOFEM, |
- | push to the reference (blessed) repository that everyone | + | |
**Before contributing, | **Before contributing, | ||
- | First, you’ll probably want to clone the main repository, create a topic branch for the patch or patch series you’re planning to contribute, and do your work there. The sequence looks basically like this: | + | First, you’ll probably want to clone the main repository, create a '' |
- | # clone reference | + | Clone reference |
$ git clone http:// | $ git clone http:// | ||
$ cd oofem.git | $ cd oofem.git | ||
- | # track remote develop | + | |
- | $ git checkout | + | Note: when a repository is cloned, git automatically creates a master |
- | # create a new brach for a new development | + | |
+ | If you already have oofem.git directory from a previous time, you can update '' | ||
+ | |||
+ | $ (git diff --name-only master | ||
+ | $ git checkout master | ||
+ | $ git pull --rebase | ||
+ | |||
+ | Normally, we do not want to modify '' | ||
$ git checkout -b featureA | $ git checkout -b featureA | ||
$ (work) | $ (work) | ||
- | | + | |
+ | Locally modified files need to be uploaded to local server. Use option '' | ||
+ | |||
+ | | ||
$ (work) | $ (work) | ||
- | $ git commit | + | $ git commit |
+ | |||
+ | |||
+ | Now, while you are working hard on your new feature, other developers complete theirs and push their changes to the remote '' | ||
+ | |||
+ | $ git checkout master | ||
+ | $ git pull --rebase | ||
+ | |||
+ | Now, to make merging your code easy, you should rebase your '' | ||
+ | |||
+ | $ git checkout featureA | ||
+ | $ git rebase master | ||
- | **It is stronlgly recommended to use '' | + | :!: **It is stronlgly recommended to use '' |
** | ** | ||
+ | |||
+ | Optionally, your branch can be merged into single '' | ||
+ | |||
+ | $ git checkout master | ||
+ | $ git merge featureA | ||
+ | $ git branch -D featureA | ||
Now you have your commits that you want to send to the maintainers. You use git format-patch to generate the mbox-formatted files that you can e-mail — it turns each commit into an e-mail message with the first line of the commit message as the subject and the rest of the message plus the patch that the commit introduces as the body. | Now you have your commits that you want to send to the maintainers. You use git format-patch to generate the mbox-formatted files that you can e-mail — it turns each commit into an e-mail message with the first line of the commit message as the subject and the rest of the message plus the patch that the commit introduces as the body. | ||
Line 147: | Line 176: | ||
The format-patch command prints out the names of the patch files it creates. The -M switch tells Git to look for renames. | The format-patch command prints out the names of the patch files it creates. The -M switch tells Git to look for renames. | ||
To e-mail this to a maintainers, | To e-mail this to a maintainers, | ||
+ | |||
+ | For those, who have write access to remote server, the local repository can be uploaded to remote server. Without any options, all branches, where local_name=remote_name will be pushed | ||
+ | |||
+ | $ git push | ||
+ | |||
+ | To be sure pushing only '' | ||
+ | |||
+ | $ git push origin master | ||
===== Maintainers ===== | ===== Maintainers ===== |
git-tutorial.txt · Last modified: 2017/11/01 09:08 by bp