# git 예제

# PX4에 코드 기여

PX4의 기능 추가는 다음 절차를 따릅니다. 다음 예제를 따라 PX4에 기여 결과를 공유할 수 있습니다.

  • 아직 Github에 계정이 없으면 가입 (opens new window)하십시오.
  • 펌웨어 코드를 복제(fork)하십시오(이곳 (opens new window) 참고)
  • 여러분의 계정으로 복제(fork)한 저장소를 로컬 컴퓨터로 가져오십시오
    cd ~/wherever/
    

git clone https://github.com//Firmware.git

* 새 디렉터리로 이동, 초기화, 하위 모듈을 업데이트한 후, 원본 업스트림 펌웨어를 추가하십시오<br>
```sh
cd Firmware
git submodule update --init --recursive
git remote add upstream https://github.com/PX4/Firmware.git
  • You should have now two remote repositories: One repository is called upstream that points to the PX4 Firmware, and one repository that points to your forked repository of the PX4 repository.
  • This can be checked with the following command:
    git remote -v
    
  • Make the changes that you want to add to the current master.
  • Create a new branch with a meaningful name that represents your feature
    git checkout -b <your feature branch name>
    
    You can verify that the push was successful by going to your forked repository in your browser: https://github.com/<your git name>/Firmware.git
    There you should see the message that a new branch has been pushed to your forked repository.
    • Add your changes that you want to be part of the commit by adding the respective files
    git add <file name>
    
    git add -p](http://nuclearsquid.com/writings/git-add/).
    • Commit the added files with a meaningful message explaining your changes
    git commit -m "<your commit message>"
    

For a good commit message, please refer to Contributing section.

  • git checkout master
    
    Then pull the newest commits from upstream master
    git pull upstream master
    
    Now your local master is up to date. Switch back to your feature branch
    git checkout <your feature branch name>
    
    and rebase on your updated master
    git rebase master
    
  • Now you can push your local commits to your forked repository
    git push origin <your feature branch name>
    
  • You can verify that the push was successful by going to your forked repository in your browser: https://github.com/<your git name>/PX4-Autopilot.git
    There you should see the message that a new branch has been pushed to your forked repository.
  • Now it's time to create a pull request (PR). On the right hand side of the "new branch message" (see one step before), you should see a green button saying "Compare & Create Pull Request". Then it should list your changes and you can (must) add a meaningful title (in case of a one commit PR, it's usually the commit message) and message (explain what you did for what reason. Check other pull requests (opens new window) for comparison)
  • You're done! Responsible members of PX4 will now have a look at your contribution and decide if they want to integrate it. Check if they have questions on your changes every once in a while.

# Get a Specific Release

If you prefer having a GUI to add your files see Gitk (opens new window) or [

  • Clone the PX4-Autopilot repo and navigate into PX4-Autopilot directory:
    git clone https://github.com/PX4/PX4-Autopilot.git
    cd PX4-Autopilot
    
  • List all releases (tags)
    git checkout master
    

git pull upstream master

* Checkout code for particular tag (e.g. for tag 1.7.4beta)
```sh
git checkout v1.7.4beta

# Update Submodule

There are several ways to update a submodule. Either you clone the repository or you go in the submodule directory and follow the same procedure as in Contributing code to PX4.

# Do a PR for a submodule update

This is required after you have done a PR for a submodule X repository and the bug-fix / feature-add is in the current master of submodule X. Since the Firmware still points to a commit before your update, a submodule pull request is required such that the submodule used by the Firmware points to the newest commit.

cd Firmware
  • Make a new branch that describes the fix / feature for the submodule update:
    git checkout -b pr-some-fix
    
  • Go to submodule subdirectory
    cd <path to submodule>
    
  • PX4 submodule might not necessarily point to the newest commit. Therefore, first checkout master and pull the newest upstream code.
    git checkout master
    git pull upstream master
    
  • Go back to Firmware directory, and as usual add, commit and push the changes.
    cd -
    

git add git commit -m "Update submodule to include ..." git push upstream pr-some-fix


## Checkout pull requests
You can test someone's pull request (changes are not yet merged) even if the branch to merge only exists on the fork from that person. Do the following
```sh
git fetch upstream  pull/<PR ID>/head:<branch name>

PR ID is the number right next to the PR's title (without the #) and the &lt;branch name&gt; can also be found right below the PR ID, e.g. &lt;the other persons git name&gt;:&lt;branch name&gt;. After that you can see the newly created branch locally with

git branch

Then switch to that branch

git checkout <branch name>

# Common pitfalls

# Force push to forked repository

After having done the first PR, people from the PX4 community will review your changes. In most cases this means that you have to fix your local branch according to the review. After changing the files locally, the feature branch needs to be rebased again with the most recent upstream/master. However, after the rebase, it is no longer possible to push the feature branch to your forked repository directly, but instead you need to use a force push:

git push --force-with-lease origin <your feature branch name>

# Rebase merge conflicts

If a conflict occurs during a git rebase, please refer to this guide (opens new window).

# Pull merge conflicts

If a conflict occurs during a git pull, please refer to this guide (opens new window).

# Build error due to git tags out of date

The build error Error: PX4 version too low, expected at least vx.x.x occurs if git tags are out of date.

This can be solved by fetching the upstream repository tags:

git fetch upstream --tags