Table of contents
- The branch for tracking state of live configuration
- Branched from PROD
- Branch for staging changes into, before releasing into PROD
- Branched from DEV
- used for independently working on new features or configuration updates
- create feature branch from DEV
- clone feature branch locally
- make modifications
- commit changes
- push changes from local feature branch into remote feature branch
- submit pull request (closing feature_branch) to merge feature branch into DEV branch. Include approver
- approver reviews pull request and fixes conflicts (checkout and update both branches locally and merge DEV into feature_branch, then conflicts will show up directly in the files for easy comparison)
- approver commits and pushes conflicts directly into feature branch if necessary which will automatically show in the original feature request
- approver approves and merges the feature branch
- all developers will see their local DEV branch now behind the remote origin, so will need to pull the changes
$ mkdir local_repo $ cd local_repo
$ git clone http://SOMESERVER.COM/REPO/NAME.git . Cloning into 'NAME'... remote: Counting objects: 35, done. remote: Compressing objects: 100% (23/23), done. remote: Total 35 (delta 15), reused 26 (delta 9) Unpacking objects: 100% (35/35), done.
$ git init
$ git config user.name "Gareth Brown"
$ git config credential.helper cache
git configto save settings for git globally instead of in
$ git config --list user.name=Gareth Brown credential.helper=cache core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
$ cd mytestproject
$ git branch -a
* master remotes/origin/HEAD -> origin/master remotes/origin/feature remotes/origin/master
Notice that it lists both the branches that are local and the remote branches on Bitbucket. Using the list as reference, choose the branch you want to checkout. In this example, the feature branch is the branch.
$ git checkout feature
$ git branch
$ git branch * feature master
Going forward, all your Git commands apply to the branch. When you push the changes to your remote Bitbucket repository, those changes apply to the repository's branch.
$ git remote add upstream http://SOMESERVER.COM/REPO/NAME.git
$ git remote -v upstream http://SOMESERVER.COM/REPO/NAME.git (fetch) upstream http://SOMESERVER.COM/REPO/NAME.git (push)
$ git fetch upstream remote: Counting objects: 35, done. remote: Compressing objects: 100% (23/23), done. remote: Total 35 (delta 15), reused 26 (delta 9) Unpacking objects: 100% (35/35), done. From http://10.102.83.61/monitoring/zabbix * [new branch] app_config_structure -> upstream/app_config_structure * [new branch] development -> upstream/development * [new branch] production -> upstream/production * [new tag] event_management -> event_management * [new tag] monitoring -> monitoring * [new tag] zabbix -> zabbix
$ git remote show upstream * remote upstream Fetch URL: http://10.102.83.61/monitoring/zabbix.git Push URL: http://10.102.83.61/monitoring/zabbix.git HEAD branch: production Remote branches: app_config_structure tracked development tracked production tracked
Add push to multiple repositoriesTo do this, you will need to create an all (or some other name) repository and update the push repo to include multiple end points.
git remote add all https://my.main-repo.com/repo.git git remote set-url --add --push all https://my.other-repo.com/repo.git git remote set-url --add --push all https://my.main-repo.com/repo.git
$ git remote -v all https://my.main-repo.com/repo.git (fetch) all https://my.other-repo.com/repo.git (push) all https://my.main-repo.com/repo.git (push)
Git and IDE
.gitignorehaving this file is important, so as to not include any unwanted files created by IDEs. For example, contents could look like the following for PyCharm
*.iml *.ipr *.iws .git .idea/*
Merge conflictsThe Bitbucket documentation on this is very clear
- Create new local branch
$ git checkout -b tidyup_files
- Commit code
$ git commit -am "some message explaining what changed"
- Push local branch and create new remote branch
$ git push -u <upstream_name> <remote_branch_name>