Skip to content

Commit d997ab1

Browse files
authored
Merge pull request #12 from Cali0707/support-master-branch-in-sync
2 parents fb7a01c + b64d1b6 commit d997ab1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ If there isn't, you can add it by doing:
1818
git remote add origin <the URL to your forked repo>
1919
```
2020

21-
3. The main branch is named `main`.
22-
`git sync` will stash any changes you have on your current branch, checkout `main`, sync it with upstream and with your fork, and then switch back to your current branch and pop off of the stash to restore your working tree and index.
21+
3. Both your git client and the git installed on your remotes support `git ls-remote --symref` (most do, just a very old version might not).
22+
23+
`git sync` will stash any changes you have on your current branch, checkout the local branch which is `HEAD` (aka the main branch) on the upstream remote,
24+
sync it with upstream and with your fork, and then switch back to your current branch and pop off of the stash to restore your working tree and index.
2325

2426
## Git Clone Fork
2527
Note: this command currently only works with github repositories!

git-sync

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
# limitations under the License.
1616

1717
echo "Synching upstream remote with origin"
18+
BRANCH="$(git ls-remote --symref origin HEAD | grep ref: | sed 's/^ref: refs\/heads\/\(.*\)[[:space:]]HEAD$/\1/')"
1819
GIT_STASH_MESSAGE="${RANDOM}"
19-
git stash push -m "{GIT_STASH_MESSAGE}"
20-
git checkout main
21-
git pull upstream main --ff-only
22-
git push origin main
20+
git stash push -m "${GIT_STASH_MESSAGE}"
21+
git checkout "${BRANCH}"
22+
git pull upstream "${BRANCH}" --ff-only
23+
git push origin "${BRANCH}"
2324
git switch -
2425
git stash list | grep "${GIT_STASH_MESSAGE}" && git stash pop 0 --index
2526
exit 0

0 commit comments

Comments
 (0)