# Git Training Workflow Example

**URL:** <https://forum.access-hive.org.au/t/git-training-workflow-example/3472>\
**Category:** Training\
**Tags:** training, workshop-2024\
**Created:** [30 August 2024 11:17 UTC](https://forum.access-hive.org.au/t/git-training-workflow-example/3472 "2024-08-30T11:17:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![harshula](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/harshula/32/256_2.png) [@harshula](https://forum.access-hive.org.au/u/harshula)\
**Post date:** [30 August 2024 11:17 UTC](https://forum.access-hive.org.au/t/git-training-workflow-example/3472/1 "2024-08-30T11:17:44Z")

</div>

1. Open an Issue:  

2. Clone the repository:

```auto
$ git clone git@github.com:ACCESS-NRI/access-spack-packages.git
$ cd access-spack-packages

```

1. If you have an old clone of the repository, make sure the main branch is up-to-date:

```auto
$ git checkout main
Already on 'main'
Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

$ git pull
Updating 81a820e..7b6a3c3
Fast-forward
 packages/mom5/package.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

```

1. Create a new branch for the changes:

```auto
$ git branch 145-access-om2-use-maintainer-function

$ git checkout 145-access-om2-use-maintainer-function
Switched to branch '145-access-om2-use-maintainer-function'

```

Or, in a single command:

```auto
$ git checkout -b 145-access-om2-use-maintainer-function

```

1. Modify the relevant files and check what has been changed:

```auto
$ git diff
diff --git a/packages/access-om2/package.py b/packages/access-om2/package.py
index 9627413..6eb1ad0 100644
--- a/packages/access-om2/package.py
+++ b/packages/access-om2/package.py
@@ -14,7 +14,7 @@ class AccessOm2(BundlePackage):
 
     git = "https://github.com/ACCESS-NRI/ACCESS-OM2.git"
 
- maintainers = ["harshula"]
+ maintainers("harshula")
 
     version("latest")
 

```

1. Commit the changes to the local repository:

```auto
$ git commit -m "access-om2: use the maintainer function" access-om2/package.py 
[145-access-om2-use-maintainer-function 2093a57] access-om2: use the maintainer function
 1 file changed, 1 insertion(+), 1 deletion(-)

```

1. Push the new commit(s) to the remote remote repository:

```auto
$ git push
fatal: The current branch 145-access-om2-use-maintainer-function has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin 145-access-om2-use-maintainer-function

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

$ git push --set-upstream origin 145-access-om2-use-maintainer-function
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 16 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 1.08 KiB | 1.08 MiB/s, done.
Total 5 (delta 3), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
remote: 
remote: Create a pull request for '145-access-om2-use-maintainer-function' on GitHub by visiting:
remote: https://github.com/ACCESS-NRI/access-spack-packages/pull/new/145-access-om2-use-maintainer-function
remote: 
To github.com:ACCESS-NRI/access-spack-packages.git
 * [new branch] 145-access-om2-use-maintainer-function -> 145-access-om2-use-maintainer-function
branch '145-access-om2-use-maintainer-function' set up to track 'origin/145-access-om2-use-maintainer-function'.

```

1. Open the Pull Request on Github:  

2. Check that the Issue is closed:  

3. After merging, some admin is recommended:

```auto
$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.

$ git fetch --all -Pp
From github.com:ACCESS-NRI/access-spack-packages
 - [deleted] (none) -> origin/145-access-om2-use-maintainer-function
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (1/1), 867 bytes | 867.00 KiB/s, done.
   7b6a3c3..03cbd36 main -> origin/main

$ git pull
Updating 7b6a3c3..03cbd36
Fast-forward
 packages/access-om2/package.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

```

1. Check that the merged commit is in the local repository’s main branch:

```auto
$ git show
commit 03cbd361481d33b010d48de024efd8d26bb35b9c (HEAD -> main, origin/main, origin/HEAD)
Author: Harshula Jayasuriya <harshula.jayasuriya@anu.edu.au>
Date: Fri Aug 30 11:07:05 2024 +1000

    access-om2: use the maintainer function (#146)

diff --git a/packages/access-om2/package.py b/packages/access-om2/package.py
index 9627413..6eb1ad0 100644
--- a/packages/access-om2/package.py
+++ b/packages/access-om2/package.py
@@ -14,7 +14,7 @@ class AccessOm2(BundlePackage):
 
     git = "https://github.com/ACCESS-NRI/ACCESS-OM2.git"
 
- maintainers = ["harshula"]
+ maintainers("harshula")
 
     version("latest")
 

```

1. The feature branch can be deleted since it is identical to `main`:

```auto
$ git diff 145-access-om2-use-maintainer-function

$ git branch -D 145-access-om2-use-maintainer-function
Deleted branch 145-access-om2-use-maintainer-function (was 2093a57).

```

1. **IMPORTANT** : Ensure other local branches are rebased with the latest `main`:

```auto
$ git checkout development
Switched to branch 'development'
Your branch is up to date with 'origin/development'.

$ git rebase main
Successfully rebased and updated refs/heads/development.

```
