Difference between revisions of "Git"
m (formatting) |
|||
(18 intermediate revisions by 11 users not shown) | |||
Line 1: | Line 1: | ||
− | Git is a version control system. It handles projects as repositories (often called | + | '''Git is a version control system.''' It handles projects as ''repositories'' (often called ''repos'') with a history. The history consists of commits. A commit is a change to the code with the description. |
− | Git allows people to create forks of a | + | Git allows people to create forks of a repository. A fork is a new repository with the same history and content, but when committing to the fork, the main repository is not affected. This allows developers to work on projects without access to the main repo. |
− | To bring other peoples work into the main | + | To bring other peoples work into the main repository, they can open a pull request. This can easily be done in the GUI of GitHub. |
Git also has the ability to create branches in one repository. This allows developers to work on multiple features at the same time. | Git also has the ability to create branches in one repository. This allows developers to work on multiple features at the same time. | ||
− | + | Luanti has two repositories: the engine is in the “<code>minetest</code>” repository, whereas the main game, Minetest Game, is in the “<code>minetest_game</code>” repositories. The repositories are hosted on GitHub. | |
− | ==Use Git to get the latest updates== | + | == Use Git to get the latest updates == |
− | You can use Git to get the latest updates of | + | |
+ | You can use Git to get the latest updates of Luanti in a <code>RUN_IN_PLACE</code> version. To do this, clone the main repository: | ||
<source lang="bash"> | <source lang="bash"> | ||
# Get the engine | # Get the engine | ||
− | git clone | + | git clone https://github.com/minetest/minetest.git luanti # Creates a directory called "luanti" with all the content. |
− | # Get | + | # Get Minetest Game |
− | cd | + | cd luanti/games/ |
− | git clone | + | git clone https://github.com/minetest/minetest_game.git # Creates a directory called "minetest_game" with all the content. |
</source> | </source> | ||
− | To get the latest updates of the engine (you have to compile | + | To get the latest updates of the engine (you have to compile Luanti after this), do this in the cloned Luanti directory: |
<source lang="bash"> | <source lang="bash"> | ||
git pull | git pull | ||
</source> | </source> | ||
− | To get the latest updates of | + | To get the latest updates of Minetest Game: |
<source lang="bash"> | <source lang="bash"> | ||
cd games/minetest_game/ | cd games/minetest_game/ | ||
Line 31: | Line 32: | ||
</source> | </source> | ||
− | == | + | == Using Git for development == |
− | |||
− | |||
− | To use Git for development you have to | + | === Creating a fork === |
+ | |||
+ | {{Template:Note|In this example only the engine repository is used, but you can do the same with the <code>minetest_game</code> repository.}} | ||
+ | |||
+ | To use Git for development, you have to fork the main repository on GitHub first. After this, you can clone your repository: | ||
<source lang="bash"> | <source lang="bash"> | ||
− | git clone git://github.com/Your_user_name_on_GitHub/minetest.git #Creates a directory called " | + | git clone git://github.com/Your_user_name_on_GitHub/minetest.git luanti #Creates a directory called "luanti" with all the content |
− | cd | + | cd luanti/ |
</source> | </source> | ||
− | ===Coding a feature=== | + | === Coding a feature or a bug fix === |
− | Create a new branch to code your feature (be sure to give them good names (not just | + | |
+ | Create a new branch to code your feature (be sure to give them good names (not just “patch” or “fix”)): | ||
<source lang="bash"> | <source lang="bash"> | ||
git checkout -b feature_branch | git checkout -b feature_branch | ||
</source> | </source> | ||
− | Now you can code your feature. If you are done you have to commit your | + | Now, you can code your feature or bug fix. If you are done, you have to commit your changes and push them to your repository on GitHub: |
<source lang="bash"> | <source lang="bash"> | ||
git add . # Adds all changes; alternatively you can specify single files | git add . # Adds all changes; alternatively you can specify single files | ||
Line 56: | Line 60: | ||
Commit messages should start with a capital letter and use the present tense. They should sum up the feature/fix. | Commit messages should start with a capital letter and use the present tense. They should sum up the feature/fix. | ||
− | You can now | + | You can now access your code in your repository on GitHub and open a pull request for it to the main repository. |
− | To go back to your master branch do: | + | To go back to your <code>master</code> branch do: |
<source lang="bash"> | <source lang="bash"> | ||
git checkout master | git checkout master | ||
</source> | </source> | ||
− | If you have to update your feature do: | + | If you have to update your feature, do: |
<source lang="bash"> | <source lang="bash"> | ||
git checkout feature_branch | git checkout feature_branch | ||
Line 71: | Line 75: | ||
git push origin feature_branch | git push origin feature_branch | ||
</source> | </source> | ||
− | |||
− | === | + | This will automatically be added to the pull request (if there is one). |
− | You can use | + | |
− | ====Prerequisites==== | + | === Updating your fork === |
+ | |||
+ | You can use Git to update your Luanti fork with the latest changes of the official repository. | ||
+ | |||
+ | ==== Prerequisites ==== | ||
+ | |||
If you haven't already you need to tell git where to get the changes. | If you haven't already you need to tell git where to get the changes. | ||
<source lang="bash"> | <source lang="bash"> | ||
− | git remote add upstream | + | git remote add upstream https://github.com/minetest/minetest |
cd games/minetest_game | cd games/minetest_game | ||
− | git remote add upstream | + | git remote add upstream https://github.com/minetest/minetest_game |
</source> | </source> | ||
− | ====Updating the | + | |
− | You need to download the changes of the main | + | ==== Updating the fork ==== |
− | For the | + | |
+ | You need to download the changes of the main repository first and then merge them. | ||
+ | |||
+ | '''For the engine:''' | ||
<source lang="bash"> | <source lang="bash"> | ||
# Get the changes | # Get the changes | ||
git fetch upstream | git fetch upstream | ||
− | # Merge the | + | # Merge the changes |
− | git | + | git rebase upstream/master |
− | # Push the result to | + | # Push the result to GitHub |
git push | git push | ||
</source> | </source> | ||
− | For the | + | |
+ | '''For the game:''' | ||
<source lang="bash"> | <source lang="bash"> | ||
cd games/minetest_game | cd games/minetest_game | ||
− | # Get the changes | + | # Get the changes: |
git fetch upstream | git fetch upstream | ||
# Merge the changes | # Merge the changes | ||
− | git | + | git rebase upstream/master |
− | # Push the result to | + | # Push the result to GitHub |
git push | git push | ||
− | </source> | + | </source><br/> |
+ | |||
+ | == Tips == | ||
+ | Simplify making commits: | ||
+ | <source lang="bash">echo 'git add -A && git commit -m "$* | ||
+ | |||
+ | $(git status -s)"' | sudo tee /usr/local/bin/gitdirectcommit && sudo chmod +x /usr/local/bin/gitdirectcommit</source> | ||
+ | to make a commit, just do changes in your repository and run e.g. <source lang="bash">gitdirectcommit my changes</source> | ||
+ | Quotes are not needed and the files (their path relative to the repository path) which are changed are annexed to the end of the commit message automatically.<br/> | ||
+ | |||
+ | == See also == | ||
− | + | * [http://git-scm.com/book ''Pro Git'' (book)] | |
− | http://git-scm.com/book | + | * [https://forum.minetest.net/viewtopic.php?f=3&t=14262 The big git and github Pull Request thread on the forums] |
+ | [[Category:Git]] |
Latest revision as of 17:57, 28 October 2024
Git is a version control system. It handles projects as repositories (often called repos) with a history. The history consists of commits. A commit is a change to the code with the description.
Git allows people to create forks of a repository. A fork is a new repository with the same history and content, but when committing to the fork, the main repository is not affected. This allows developers to work on projects without access to the main repo.
To bring other peoples work into the main repository, they can open a pull request. This can easily be done in the GUI of GitHub.
Git also has the ability to create branches in one repository. This allows developers to work on multiple features at the same time.
Luanti has two repositories: the engine is in the “minetest
” repository, whereas the main game, Minetest Game, is in the “minetest_game
” repositories. The repositories are hosted on GitHub.
Use Git to get the latest updates
You can use Git to get the latest updates of Luanti in a RUN_IN_PLACE
version. To do this, clone the main repository:
# Get the engine
git clone https://github.com/minetest/minetest.git luanti # Creates a directory called "luanti" with all the content.
# Get Minetest Game
cd luanti/games/
git clone https://github.com/minetest/minetest_game.git # Creates a directory called "minetest_game" with all the content.
To get the latest updates of the engine (you have to compile Luanti after this), do this in the cloned Luanti directory:
git pull
To get the latest updates of Minetest Game:
cd games/minetest_game/
git pull
Using Git for development
Creating a fork
minetest_game
repository.
To use Git for development, you have to fork the main repository on GitHub first. After this, you can clone your repository:
git clone git://github.com/Your_user_name_on_GitHub/minetest.git luanti #Creates a directory called "luanti" with all the content
cd luanti/
Coding a feature or a bug fix
Create a new branch to code your feature (be sure to give them good names (not just “patch” or “fix”)):
git checkout -b feature_branch
Now, you can code your feature or bug fix. If you are done, you have to commit your changes and push them to your repository on GitHub:
git add . # Adds all changes; alternatively you can specify single files
git commit -m "Your feature"
git push origin feature_branch
Commit messages should start with a capital letter and use the present tense. They should sum up the feature/fix.
You can now access your code in your repository on GitHub and open a pull request for it to the main repository.
To go back to your master
branch do:
git checkout master
If you have to update your feature, do:
git checkout feature_branch
# Do changes
git add .
git commit -m "Update message"
git push origin feature_branch
This will automatically be added to the pull request (if there is one).
Updating your fork
You can use Git to update your Luanti fork with the latest changes of the official repository.
Prerequisites
If you haven't already you need to tell git where to get the changes.
git remote add upstream https://github.com/minetest/minetest
cd games/minetest_game
git remote add upstream https://github.com/minetest/minetest_game
Updating the fork
You need to download the changes of the main repository first and then merge them.
For the engine:
# Get the changes
git fetch upstream
# Merge the changes
git rebase upstream/master
# Push the result to GitHub
git push
For the game:
cd games/minetest_game
# Get the changes:
git fetch upstream
# Merge the changes
git rebase upstream/master
# Push the result to GitHub
git push
Tips
Simplify making commits:
echo 'git add -A && git commit -m "$*
$(git status -s)"' | sudo tee /usr/local/bin/gitdirectcommit && sudo chmod +x /usr/local/bin/gitdirectcommit
to make a commit, just do changes in your repository and run e.g.
gitdirectcommit my changes
Quotes are not needed and the files (their path relative to the repository path) which are changed are annexed to the end of the commit message automatically.