[Guide] Common Git repository operations

Users who are viewing this thread

Read the Git installation and setup guide before following this one. This guide also uses Git Extensions for the examples; if you are using another Git client you will have to try convert the base concepts across.

Opening the repository in Git Extensions:
  • Start Git Extensions, then either select your PW repository from the "Recent Repositories" list, or use "Open repository" and find it manually.
    open_1.png
  • The main repository browsing window should look something like this.
    open_2.png
Browsing the history:
  • From the main repository browsing window, you can select commits in the upper "log" pane, then click the "Commit" tab to view the message, author, and other information about the commit. Screenshot as above.
  • The "Files" tab allows browsing the contents of each file in the repository at that commit.
    browse_log_1.png
  • The "Diff" tab displays the differences in files compared to the previous commit.
    browse_log_2.png
Checking out an existing local or remote branch:
  • You can select local branches (made on your computer) from the list box in the middle of the tool bar, or choose "Checkout branch" from the Commands menu.
    check_out_1.png
  • To check out remote branches and make a local branch to track them with, choose "Checkout branch" from the Commands menu: click the "Remote branch" radio button, then select the branch from the list box and press "Checkout".
Creating a new branch for your own changes:
  • Branches are very "cheap" in Git, and you should always make changes to the module system files in a branch you created, not the main "native" or "pw" branches tracking the official "origin" remote branches: otherwise you won't be able to compare with the official branches easily, and pulling updates will create merges and conflicts even if you only wanted to look at the changes.
  • Choose "Create branch" from the Commands menu: select the commit you want to base on in the log window, give the branch a descriptive name, then click "Create branch".
    create_branch_1.png
Committing changes to a branch you created:
  • Pretending you had a good coding session and added multiple different things to your module system before remembering to commit them, first build the module to check for obvious errors, also testing in game if necessary.
  • Switch into Git Extensions and click the "Commit" button in the middle of the tool bar, or choose it from the "Command" menu: a window like this will appear (remember to commit to a branch of your own). Notice the two file lists at the left side of the window, top is "unstaged" (new changes), bottom is "staged" (changes added for the next commit).
    commit_1.png
  • Since the different changes don't belong together in one logical commit, select the lines for one feature, right click, and choose "Stage selected line(s)" or press S.
    commit_2.png
  • Notice that the changes have now disappeared from the module_items.py diff in the unstaged section.
    commit_3.png
  • And appeared in the module_items.py diff in the staged section. Add a short descriptive commit message in the box at the lower right, then click "Commit".
    commit_4.png
  • You will be back to the main log window with your new commit visible at the tip of the current branch. Click "Commit" again to continue adding the other changes.
    commit_5.png
  • If all the changes in a file are related to a single commit, select it and press the "Stage" button. The "Unstage" button removes files from being included in the next commit if you made a mistake, and you can also select single lines to remove in the diff view.
    commit_6.png
  • If you click the "Amend Commit" check box, the changes will be added on to the last commit rather than making a new one. Only use this to fix recent mistakes: don't do it after "pushing" your changes to a public repository where other people might have "pulled" (downloaded) it, otherwise they will get a merge conflict to fix, or worse.
Pulling updates from the official github repository:
  • The github repository is where you downloaded the original data from, so it is named "origin" by default. You can add other "remotes" (repositories to pull changes from) if other people make them.
  • Change to the "pw" branch as explained above, committing or stashing any unsaved changes first.
  • Click the "pull" button in the tool bar (down arrow) or choose "Pull" from the "Commands" menu.
  • Ensure the merge options radio button is on "Rebase" (there shouldn't be anything to merge, but just in case), then click "Pull".
This list of guides is still a bit unfinished: I ran out of time. It will be completed later.
 
Back
Top Bottom