Git Workflow
Use the following process to send production code updates to Alan.
Please note that this use case assumes that you haven't actually comitted anything to your module's branch while working. A tutorial for that use case will be created at some point in the future.
Get the latest version of the
devbranch.> git branch master * dev > git status On branch dev Your branch is behind 'origin/dev' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) nothing to commit, working tree clean > git pull Updating d4ef1e5e..0180e4e7 Fast-forward public_html/utility_remove_empire_v16.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) > git status On branch dev Your branch is up to date with 'origin/dev'. nothing to commit, working tree cleanCheckout a new branch from
devto work on your module. Example:> git checkout -b federation Switched to a new branch 'federation'Once you are ready to submit your code for a production update, copy changed files into the
testfolder as usualWhile your module's branch is checked out, add and commit ONLY the test folder (unless you really know what you are doing). For example:
Make sure you are on the correct branch:
> git branch master dev * federation some-other-moduleYou should always check on the status of the working tree before performing git operations:
> git status On branch federation Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: public_html/modules/federation/module.js Untracked files: (use "git add <file>..." to include in what will be committed) public_html/media/images/heraldry/empire/70_eheraldry/70462_eheraldry.png test/whynotd/federation/module.js no changes added to commit (use "git add" and/or "git commit -a")Stage the test folder to be comitted
> git add testAgain, check on the status of the working tree:
> git status On branch federation Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: test/whynotd/federation/module.js Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: public_html/modules/federation/module.js Untracked files: (use "git add <file>..." to include in what will be committed) public_html/media/images/heraldry/empire/70_eheraldry/70462_eheraldry.pngCommit the files in staging (in this case, we would be comitting
test/whynotd/federation/module.js):> git commit -m 'adding updated federation module to test folder' [federation 67aa0ff9] adding updated federation module to test folder 1 file changed, 4320 insertions(+) create mode 100644 test/whynotd/federation/module.jsAgain, check on the status of the working tree:
> git status On branch federation Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: public_html/modules/federation/module.js Untracked files: (use "git add <file>..." to include in what will be committed) public_html/media/images/heraldry/empire/70_eheraldry/70462_eheraldry.png no changes added to commit (use "git add" and/or "git commit -a")Discard changes you made outside of the
testfolder:> git checkout -- . > git status On branch federation Untracked files: (use "git add <file>..." to include in what will be committed) public_html/media/images/heraldry/empire/70_eheraldry/70462_eheraldry.png nothing added to commit but untracked files present (use "git add" to track)"Clean up" any untracked files. WARNING: this will delete the untracked files.
> git clean -f ./**/* ./* Removing public_html/media/images/heraldry/empire/70_eheraldry/70462_eheraldry.pngMake sure the working tree is clean:
> git status On branch federation nothing to commit, working tree clean
Update your local dev branch with any changes from the remote:
> git fetch > git checkout dev Switched to branch 'dev' Your branch is behind 'origin/dev' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) > git pull Updating 0180e4e7..0d2d660f Fast-forward README.md | 13 + 1 file changed, 13 insertion(+) create mode 100644 README.mdSwitch back to your module's branch:
> git checkout federation Switched to branch 'federation'Merge
devinto your module's branch:> git merge devIf there are no merge conflicts, this will open your default git text editor.
This tutorial will use vim as the default editor. You can see your default text editor with the following command:
> git config --global --get core.editor nanoRecommended: To change your default editor to vim, run the following command:
> git config --global core.editor "vim"Vim can be difficult to use for beginners. Follow the next set of instructions carefully.
Again, if there are no merge conflicts, vim will open with a default commit message:
Merge branch 'dev' into federation # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit. ~ ~ "/var/www/html/stariumxcv.dev/.git/MERGE_MSG" 7L, 258CAccept the default commit message by typing :x and then hitting enter:
Merge branch 'dev' into federation # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit. ~ ~ :xNote that you do not need to navigate to the bottom of the file to do this. Simply leave the cursor where it is and enter the commands above.
You should now return to the shell prompt with the following output:
Merge made by the 'recursive' strategy. README.md | 13 + 1 file changed, 13 insertions(+) create mode 100644 README.md
If there are merge conflicts, the merge will abort with the output that looks something like the following:
> git merge dev Auto-merging README.md CONFLICT (add/add): Merge conflict in README.md Automatic merge failed; fix conflicts and then commit the result.Please refer to the documentation on resolving merge conflicts here.
You can return to this tutorial when you have resolved the conflicts and are back to a clean working tree.
Check the status of the working tree:
> git status On branch federation nothing to commit, working tree cleanSwitch back to the dev branch:
> git checkout dev Switched to branch 'dev' Your branch is up to date with 'origin/dev'.Merge your module's branch into dev. There should not be any merge conflicts, nor should vim open as we have already resolved any conflicts.
> git merge federation Updating 0d2d660f..0a4846ac Fast-forward test/whynotd/federation/module.js | 4320 + 1 file changed, 4320 insertions(+) create mode 100644 test/whynotd/federation/module.js > git status On branch dev Your branch is ahead of 'origin/dev' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working tree cleanPush your code to the remote:
> git push Enumerating objects: 14, done. Counting objects: 100% (12/12), done. Delta compression using up to 12 threads Compressing objects: 100% (7/7), done. Writing objects: 100% (8/8), 24.12 KiB | 4.02 MiB/s, done. Total 8 (delta 4), reused 0 (delta 0) To repo.stariumxcv.com:/~/code/stariumxcv.dev.git 0d2d660f..0a4846ac dev -> dev > git status On branch dev Your branch is up to date with 'origin/dev'. nothing to commit, working tree clean
That's it! You can now go back to your module's branch and continue working.
Repeat this process when you are ready to add more changes.
Again, this use case assumes that you haven't actually comitted anything to your module's branch while working. If you do want to commit to your module's branch while you are working on it but before you move it to the test folder, get in touch with David on discord for help.