work:gitusage
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| work:gitusage [2013/05/15 16:57] – [Adding Useful Aliases] alun | work:gitusage [2022/01/31 10:46] (current) – alunwcom | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Using git ====== | ||
| + | ===== Possible Workflows ===== | ||
| + | |||
| + | It is important that we adopt a workflow to use with git - otherwise branching and merging will be disorganized. This is important to allow distributed/ | ||
| + | |||
| + | There seem to be a number of options out there - documented in varying levels of detail on the web. | ||
| + | |||
| + | gitflow seems to be a fairly established workflow, Scott Chacon (a developer at github, and writer of [[http:// | ||
| + | |||
| + | I think gitflow provides a good starting point however, and we could modify the exact branching structure as required. | ||
| + | |||
| + | gitflow explained: http:// | ||
| + | |||
| + | Scott Chacon' | ||
| + | |||
| + | Though I like the idea of deploying often - I don't think we are likely to reach the ' | ||
| + | |||
| + | Branch names should be meaningful (adopting conventions as appropriate) - for sure. | ||
| + | |||
| + | Pull requests for internal code reviews need to be examined further... | ||
| + | |||
| + | Both appear to agree not to work directly on the deployable branch (' | ||
| + | |||
| + | ==== Other options: ==== | ||
| + | |||
| + | Branch-per-feature: | ||
| + | |||
| + | Git Book workflows: http:// | ||
| + | |||
| + | ==== Misc: ==== | ||
| + | |||
| + | http:// | ||
| + | |||
| + | http:// | ||
| + | |||
| + | http:// | ||
| + | |||
| + | http:// | ||
| + | |||
| + | ===== Pull Requests ===== | ||
| + | |||
| + | [TODO] https:// | ||
| + | |||
| + | ===== Automation - Continuous Integration and Deployments, | ||
| + | |||
| + | [TODO] | ||
| + | |||
| + | ===== Hosting ===== | ||
| + | |||
| + | Should we be hosting git ourselves - or have it hosted elsewhere? If so, where? | ||
| + | |||
| + | I think most workflow models agree that, despite the benefits of working with distributed repositories, | ||
| + | |||
| + | (We would need to consider whether we would want to prevent history re-writing in this central repo.) | ||
| + | |||
| + | So where would we host this central repo? In particular, do we want to have to provision, set-up, and maintain a server to provide this repo? Answer is probably no. | ||
| + | |||
| + | There are a number of hosted services available - with the frontrunners probably being gitHub and BitBucket. GitHub, I think, is the original git hosting solution - and hosts many open source projects. BitBucket appears to be trying to rival GitHub, and I have found it useful for private projects (which GitHub won't host for free). This reflects differences in their pricing model. | ||
| + | |||
| + | I think it is pointless agonizing too much over our choice, simple due diligence and a team straw-poll should suffice - as it should be pretty straightforward to clone repos and migrate from one provider to another (though this may be a pain). | ||
| + | |||
| + | We will have backups of our repositories on every developer PC, and if we are really paranoid (or cautious?) we can keep cloned and regularly updated versions of the repos on a Wiley server somewhere (Oxford?) - updated by cron script. | ||
| + | |||
| + | Both GitHub and BitBucket have enterprise offerings that allow you to run their software inside your firewall - but for our set-up I can't see the benefit of this. | ||
| + | |||
| + | Assuming we are a fairly static team size (though I don't know how many outsourced developers will need access), and we may wish to create any number of private repos - then I believe the BitBucket pricing is better. | ||
| + | |||
| + | https:// | ||
| + | |||
| + | https:// | ||
| + | |||
| + | |||
| + | ===== Basics ===== | ||
| + | |||
| + | Git book: http:// | ||
| + | |||
| + | [TODO] | ||
| + | |||
| + | ==== Feature Branch: Create, Commit, Merge, Delete ==== | ||
| + | |||
| + | Create Feature Branch, Commit: | ||
| + | |||
| + | $ git checkout -b feature-001 master | ||
| + | $ vi file123 | ||
| + | $ git commit -a | ||
| + | $ git push origin feature-001 | ||
| + | |||
| + | Merge, Delete, Push: | ||
| + | |||
| + | $ git checkout master | ||
| + | $ git merge --no-ff feature-001 | ||
| + | $ git push origin master | ||
| + | $ git branch -d feature-001 | ||
| + | $ git push origin : | ||
| + | |||
| + | In Eclipse, it is possible to import (clone) a project from Git - and then a new feature branch can be created using the ' | ||
| + | |||
| + | Ah! Issue: Cannot merge with no fast-forward in eGit yet. See links below... | ||
| + | |||
| + | http:// | ||
| + | |||
| + | https:// | ||
| + | |||
| + | ==== Moving to a New Repo ==== | ||
| + | |||
| + | If you have started working in one repo, but then need to move elsewhere: | ||
| + | |||
| + | 1. Create new empty repo in new location (this may vary but if creating directly from command-line): | ||
| + | |||
| + | $ cd / | ||
| + | $ mkdir jhpplugin.git | ||
| + | $ cd jhpplugin.git/ | ||
| + | $ git init --bare | ||
| + | | ||
| + | 2. Change remote location on your local machine and then push to new location (ensure you've got the latest changes from your old location first, of course): | ||
| + | $ git remote -v | ||
| + | origin | ||
| + | origin | ||
| + | $ git remote set-url origin ssh:// | ||
| + | $ git remote -v | ||
| + | origin | ||
| + | origin | ||
| + | $ git push -u origin --all | ||
| + | $ git push -u origin --tags | ||
| + | |||
| + | 2b. If you haven' | ||
| + | $ git remote add origin ssh:// | ||
| + | | ||
| + | Job done. Now remember to tell everyone to use the new location ; | ||
| + | |||
| + | 3. Moving existing local copies: | ||
| + | $ git remote -v | ||
| + | origin | ||
| + | origin | ||
| + | $ git remote set-url origin ssh:// | ||
| + | $ git remote -v | ||
| + | origin | ||
| + | origin | ||
| + | |||
| + | 4. Linking to new remote repo: | ||
| + | $ cd / | ||
| + | $ git remote add origin [email protected]: | ||
| + | $ git push -u origin --all # pushes up the repo and its refs for the first time | ||
| + | $ git push -u origin --tags # pushes up any tags | ||
| + | |||
| + | ===== Misc. ===== | ||
| + | |||
| + | ==== Adding Useful Aliases ==== | ||
| + | |||
| + | 31-Jan-2022: | ||
| + | [alias] | ||
| + | co = checkout | ||
| + | st = status | ||
| + | lg = log --graph --all --pretty=format:' | ||
| + | lgc = log --graph --pretty=format:' | ||
| + | lgf = log --graph --all --pretty=format:' | ||
| + | |||
| + | Currently adding short status alias, and pretty log alias: | ||
| + | |||
| + | $ git config --global alias.st status | ||
| + | #$ git config --global alias.lg "log --graph --pretty=format:' | ||
| + | | ||
| + | $ git config --global alias.lg "log --graph --pretty=format:' | ||
| + | | ||
| + | Other options... | ||
| + | | ||
| + | $ git config --global alias.lg "log --graph --pretty=format:' | ||
| + | | ||
| + | $ git config --global --unset alias.lg | ||
| + | | ||
| + | ==== BitBucket SSH issue on Linux ==== | ||
| + | |||
| + | I've experienced this error when working with BitBucket on Centos6: | ||
| + | |||
| + | $ git clone https:// | ||
| + | Initialized empty Git repository in / | ||
| + | | ||
| + | (gnome-ssh-askpass: | ||
| + | |||
| + | The problem is that I am running the command in a Putty session, while an environment variable (SSH_ASKPASS) is specifying a Gnome dialog: | ||
| + | |||
| + | $ echo $SSH_ASKPASS | ||
| + | / | ||
| + | |||
| + | This can be unset temporarily, | ||
| + | |||
| + | ==== GitHub CLI Cloning ==== | ||
| + | |||
| + | The gotcha here is that although the GitHub front-end shows the https repository URL as being read+write access - this isn't actually the case. You need SSH access in order to write. Or you get this error: | ||
| + | |||
| + | $ git push origin master | ||
| + | error: The requested URL returned error: 403 while accessing https:// | ||
| + | | ||
| + | fatal: HTTP request failed | ||
| + | |||
| + | If you've just cloned the repository using the HTTPS URL, this means editing the remote URL: | ||
| + | |||
| + | $ git clone https:// | ||
| + | ... | ||
| + | $ git remote -v | ||
| + | origin | ||
| + | origin | ||
| + | $ git remote set-url origin ssh:// | ||
| + | | ||
| + | NOTE: You will have also had to set-up SSH public key access or you will hit this error: | ||
| + | |||
| + | $ git push origin master | ||
| + | Permission denied (publickey). | ||
| + | fatal: The remote end hung up unexpectedly | ||
| + | |||
| + | Generating keys for GitHub is covered here: https:// | ||
| + | |||
| + | This is a brief version: | ||
| + | |||
| + | $ ssh-keygen -t rsa -C " | ||
| + | ... | ||
| + | Enter passphrase (empty for no passphrase): | ||
| + | Enter same passphrase again: | ||
| + | Your identification has been saved in / | ||
| + | Your public key has been saved in / | ||
| + | ... | ||
| + | | ||
| + | $ cat ~/ | ||
| + | ... | ||
| + | |||
| + | NOTE: If you already have a public key generated, you will be prompted to overwrite it if you generate a new key. | ||
| + | |||
| + | The public key can then be added to GitHub here: https:// | ||
| + | |||
| + | ==== Forking ==== | ||
| + | |||
| + | [TODO] | ||
| + | |||
| + | Fork in GitHub or BitBucket. | ||
| + | |||
| + | Clone your forked repo locally to work on. | ||
| + | |||
| + | Add an extra upstream remote repo pointing to the original forked repo (so you can get updates to the original repo): | ||
| + | |||
| + | $ git remote -v | ||
| + | origin ssh:// | ||
| + | origin ssh:// | ||
| + | | ||
| + | $ git remote add upstream https:// | ||
| + | $ git remote -v | ||
| + | origin ssh:// | ||
| + | origin ssh:// | ||
| + | upstream https:// | ||
| + | upstream https:// | ||
| + | | ||
| + | $ git fetch upstream | ||
| + | ... | ||
| + | $ git merge upstream/ | ||
| + | ... | ||
| + | | ||
| + | | ||
| + | $ git push origin master | ||
| + | ... | ||
| + | |||
| + | ==== Setting Eclipse Project to Work with BitBucket ==== | ||
| + | |||
| + | Having set-up a local repository - and its hosted counter-part - you need to configure this remote repository. | ||
| + | |||
| + | Use Team > Remote > Configure Push to Upstream | ||
| + | |||
| + | From the dialog box, select Advanced... and then Add All Branches Spec (and Add All Tags Spec). | ||
| + | |||
| + | Ditto for fetch?? | ||
| + | |||
| + | |||
| + | In 'Git Repositories' | ||
| + | |||
| + | key: branch.master.remote | ||
| + | value: origin | ||
| + | | ||
| + | key: branch.master.merge | ||
| + | value: refs/ | ||
| + | |||
| + | This can be edited directly in the Git repository (.git/ | ||
| + | |||
| + | [branch " | ||
| + | remote = origin | ||
| + | merge = refs/ | ||
| + | |||
| + | ==== Working with GitHub in Eclipse ==== | ||
| + | |||
| + | Issue here is that GitHub will want to use SSH... | ||
| + | |||
| + | http:// | ||
| + | |||
| + | (I'm going to try and re-use the SSH certificate I generated previously for Linux CLI GitHub access.) | ||
| + | |||
| + | In Eclipse: | ||
| + | |||
| + | * Window > Preferences: | ||
| + | * Create new RSA key in Key Management tab. | ||
| + | * Check that this key is included under the General tab. | ||
| + | * Upload this (public) key to GitHub (account settings). | ||
| + | * Git Repositories: | ||
| + | * Edit the remote URI from https format to ssh. E.g.: < | ||
| + | https:// | ||
| + | * Save and Push | ||
| + | |||
| + | Done. Now want to add upstream remote for dotCMS/ | ||
| + | |||
| + | ===== Gitflow ===== | ||
| + | |||
| + | CLI (tried below on Centos6): https:// | ||
| + | |||
| + | ==== Create repo ==== | ||
| + | |||
| + | $ mkdir gitflow-test | ||
| + | $ cd gitflow-test/ | ||
| + | $ git flow init | ||
| + | Initialized empty Git repository in / | ||
| + | No branches exist yet. Base branches must be created now. | ||
| + | Branch name for production releases: [master] | ||
| + | Branch name for "next release" | ||
| + | | ||
| + | How to name your supporting branch prefixes? | ||
| + | Feature branches? [feature/] | ||
| + | Release branches? [release/] | ||
| + | Hotfix branches? [hotfix/] | ||
| + | Support branches? [support/] | ||
| + | Version tag prefix? [] v | ||
| + | | ||
| + | $ git status | ||
| + | # On branch develop | ||
| + | nothing to commit (working directory clean) | ||
| + | |||
| + | ==== Working on a Feature ==== | ||
| + | |||
| + | $ git flow feature list | ||
| + | No feature branches exist. | ||
| + | | ||
| + | You can start a new feature branch: | ||
| + | | ||
| + | git flow feature start < | ||
| + | | ||
| + | $ git flow feature start initial-coding | ||
| + | Switched to a new branch ' | ||
| + | | ||
| + | Summary of actions: | ||
| + | - A new branch ' | ||
| + | - You are now on branch ' | ||
| + | | ||
| + | Now, start committing on your feature. When done, use: | ||
| + | | ||
| + | git flow feature finish initial-coding | ||
| + | | ||
| + | $ git flow feature list | ||
| + | * initial-coding | ||
| + | |||
| + | ...added stuff for feature... | ||
| + | | ||
| + | $ git status | ||
| + | # On branch feature/ | ||
| + | # Changes to be committed: | ||
| + | # (use "git reset HEAD < | ||
| + | # | ||
| + | # new file: | ||
| + | # new file: | ||
| + | # | ||
| + | |||
| + | Belatedly added remote.. | ||
| + | | ||
| + | $ git remote add origin https:// | ||
| + | $ git push -u origin --all | ||
| + | Password: | ||
| + | Counting objects: 2, done. | ||
| + | Writing objects: 100% (2/2), 167 bytes, done. | ||
| + | Total 2 (delta 0), reused 0 (delta 0) | ||
| + | remote: bb/acl: alunwcom is allowed. accepted payload. | ||
| + | To https:// | ||
| + | * [new branch] | ||
| + | * [new branch] | ||
| + | * [new branch] | ||
| + | Branch develop set up to track remote branch develop from origin. | ||
| + | Branch feature/ | ||
| + | Branch master set up to track remote branch master from origin. | ||
| + | |||
| + | Finish feature (which doesn' | ||
| + | |||
| + | $ git flow feature finish initial-coding | ||
| + | Switched to branch ' | ||
| + | Updating 242a2ed..8133d20 | ||
| + | Fast-forward | ||
| + | | ||
| + | | ||
| + | 2 files changed, 13 insertions(+), | ||
| + | | ||
| + | | ||
| + | Deleted branch feature/ | ||
| + | | ||
| + | Summary of actions: | ||
| + | - The feature branch ' | ||
| + | - Feature branch ' | ||
| + | - You are now on branch ' | ||
| + | |||
| + | # [ISSUE?] Finishing the feature appears to have merged with fast-forward, | ||
| + | | ||
| + | # [ISSUE?] Had to remote remote branch manually - maybe because I didn't use ' | ||
| + | $ git push origin : | ||
| + | ... | ||
| + | |||
| + | Release.. | ||
| + | |||
| + | $ git flow release start 0.1 | ||
| + | Branches ' | ||
| + | And local branch ' | ||
| + | Switched to a new branch ' | ||
| + | | ||
| + | Summary of actions: | ||
| + | - A new branch ' | ||
| + | - You are now on branch ' | ||
| + | | ||
| + | Follow-up actions: | ||
| + | - Bump the version number now! | ||
| + | - Start committing last-minute fixes in preparing your release | ||
| + | - When done, run: | ||
| + | | ||
| + | git flow release finish ' | ||
| + | | ||
| + | $ git push --all | ||
| + | | ||
| + | $ git flow release finish 0.1 | ||
| + | ... | ||
| + | | ||
| + | $ git push --all | ||
| + | | ||
| + | $ git push origin : | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | | ||
