Skip to content

Commit

Permalink
Add aliases for topic-start and topic-finish
Browse files Browse the repository at this point in the history
  • Loading branch information
joelparkerhenderson committed Feb 19, 2025
1 parent 3654409 commit 80a6c79
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,10 @@ Use graphviz:
* [git topic-*](doc/git-topic/) - Read this first about topic aliases
* [git topic-base-branch](doc/git-topic-base-branch/) - Show the project base topic branch name
* [git topic-move](doc/git-topic-move/) - Rename the current topic branch
* [git topic-begin](doc/git-topic-begin/) - Start a new topic branch
* [git topic-end](doc/git-topic-end/) - Finish the current topic branch
* [git topic-begin](doc/git-topic-begin/) - Begin a new topic branch, same as topic-start
* [git topic-end](doc/git-topic-end/) - End the current topic branch; same as topic-finish
* [git topic-finish](doc/git-topic-finish/) - Finish the current topic branch; same as topic-end
* [git topic-start](doc/git-topic-start/) - Start a new topic branch; same as topic-begin
* [git topic-sync](doc/git-topic-sync/) - Synchronize the current topic branch by doing updates
* [git track-all-remote-branches](doc/git-track-all-remote-branches/) - Track all remote branches that aren't already being tracked
* [git track](doc/git-track/) - Start tracking a branch, with default parameters, and showing the command
Expand Down
5 changes: 5 additions & 0 deletions doc/git-topic-begin/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Example:
git topic-begin add-feature-foo
```

This alias comes in two flavors for your preference:

* topic-begin
* topic-start

Customize this alias as you like for your own workflow.

We use this alias to begin work on a new feature,
Expand Down
5 changes: 5 additions & 0 deletions doc/git-topic-end/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Example:
git topic-end
```

This alias comes in two flavors for your preference:

* topic-end
* topic-finish

Customize this alias as you like for your own workflow.

This must be the current branch.
Expand Down
1 change: 1 addition & 0 deletions doc/git-topic-finish/README.md
62 changes: 62 additions & 0 deletions doc/git-topic-finish/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# git topic-finish

## Finish the current topic branch

Git alias:

```git
topic-finish = "!f(){ \
new_branch=$(git current-branch); \
old_branch=$(git topic-base-branch); \
if [ \"$new_branch\" = \"$old_branch\" ]; then \
printf \"You are asking to do git topic-end,\n\"; \
printf \"but you are not on a new topic branch;\n\"; \
printf \"you are on the base topic branch: $old_branch.\n\"; \
printf \"Please checkout the topic branch that you want,\n\"; \
printf \"then retry the git topic-end command.\n\"; \
else \
git push; \
git checkout \"$old_branch\"; \
git branch --delete \"$new_branch\"; \
git push origin \":$new_branch\"; \
fi; \
};f"
```

Example:

```shell
git topic-finish
```

This alias comes in two flavors for your preference:

* topic-finish
* topic-end

Customize this alias as you like for your own workflow.

This must be the current branch.

We use this alias to complete work on a new feature,
new task, new fix, new refactor, new optimization, etc.

Our workflow does these steps:

1. Push the topic branch.

2. Delete the topic branch locally.

3. Delete the topic branch remotely.

If you use a sharing site such a GitHub, and use typical settings,
then this implementation deletes your branch for the site.

Many teams choose to delete topic branches when they are finished,
to keep the repositories clean and with a smaller number of branches.

If git says "unable to push to unqualified destination" then it means
that the remote branch doesn't exist, so git is unable to delete it;
that message is typically ok because it means that someone else has
already deleted the branch. To synchronize your branch list, you can
use "git fetch --prune".
1 change: 1 addition & 0 deletions doc/git-topic-start/README.md
46 changes: 46 additions & 0 deletions doc/git-topic-start/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# git topic-start

## Start a new topic branch

Git alias:

```git
topic-start = "!f(){ \
new_branch=\"$1\"; \
old_branch=$(git topic-base-branch); \
git checkout \"$old_branch\"; git pull; \
git checkout -b \"$new_branch\" \"$old_branch\"; \
git push --set-upstream origin \"$new_branch\"; \
};f"
```

Example:

```shell
git topic-start add-feature-foo
```

This alias comes in two flavors for your preference:

* topic-start
* topic-begin

Customize this alias as you like for your own workflow.

We use this alias to begin work on a new feature,
new task, new fix, new refactor, new optimization, etc.

Our workflow does these steps:

1. Update the base topic branch.

2. Create a new topic branch based on the topic base branch name,

3. Push the new topic branch, so team members can see it.

If you use a sharing site such a GitHub, and use typical settings,
then this implementation makes your branch visible to collaborators.

Many teams share branches before they are fully ready, to help
the team provide feedback on the work-in-progress, and also to
run any automatic tests to verify the branch runs successfully.
26 changes: 21 additions & 5 deletions gitalias.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@

### add aliases ###

## add all
# add all
aa = add --all

# add by patch - looks at each change, and asks if we want to put it in the repo.
# add by patch - look at each change, and asks if we want to put it in the repo.
ap = add --patch

# add just the files that are updated.
Expand Down Expand Up @@ -1623,7 +1623,13 @@
#
# Example:
#
# git topic-begin add-feature-foo
# git topic-start add-feature-foo
#
# These aliases are identical and are for people
# who prefer the word "start" or the word "begin":
#
# * topic-start
# * topic-begin
#
# We use this alias to begin work on a new feature,
# new task, new fix, new refactor, new optimization, etc.
Expand All @@ -1643,7 +1649,7 @@
# the team provide feedback on the work-in-progress, and also to
# run any automatic tests to verify the branch runs successfully.
topic-begin = "!f(){ \
topic-start = "!f(){ \
new_branch=\"$1\"; \
old_branch=\"$(git topic-base-branch)\"; \
git checkout \"$old_branch\"; \
Expand All @@ -1652,11 +1658,19 @@
git push --set-upstream origin \"$new_branch\"; \
};f"
topic-begin = topic-start
# Stop a topic branch; this must be the current branch.
#
# Example:
#
# git topic-end
# git topic-finish
#
# These aliases are identical and are for people
# who prefer the word "finish" or the word "end":
#
# * topic-finish
# * topic-end
#
# We use this alias to complete work on a new feature,
# new task, new fix, new refactor, new optimization, etc.
Expand Down Expand Up @@ -1697,6 +1711,8 @@
fi; \
};f"
topic-end = topic-finish
# Update the current topic branch by synchronizing changes.
#
# Example:
Expand Down

0 comments on commit 80a6c79

Please sign in to comment.