GitBridge provides flexible options for synchronizing specific branches, tags, or commits from your GitHub repository. This guide covers all aspects of managing different repository references.
# Sync specific branchgitbridgesync--repohttps://github.com/user/repo\--local~/projects/repo\--refdevelop
# Sync specific taggitbridgesync--repohttps://github.com/user/repo\--local~/projects/repo\--refv1.2.3
# Sync specific commitgitbridgesync--repohttps://github.com/user/repo\--local~/projects/repo\--refabc123def456789
# List all branchesgitbridgelist-branches--repohttps://github.com/user/repo
# Output:# Available branches:# * main (default)# - develop# - feature/new-feature# - hotfix/urgent-fix
# Switch to different branchgitbridgesync--configconfig.yaml--reffeature/new-feature
# This will:# 1. Fetch the new branch# 2. Update local files to match# 3. Update metadata for tracking
# List all tagsgitbridgelist-tags--repohttps://github.com/user/repo
# List tags with patterngitbridgelist-tags--repohttps://github.com/user/repo--pattern"v*"# Output:# Available tags:# - v2.0.0 (latest)# - v1.2.3# - v1.2.2# - v1.2.1
fromgitbridge.repository_managerimportRepositoryManagerfromgitbridge.api_clientimportGitHubAPIClient# Create managersclient=GitHubAPIClient(session,repo_url)repo_mgr=RepositoryManager(client,repo_url)# Resolve reference to SHAsha=repo_mgr.resolve_ref("main")print(f"main branch is at: {sha}")# Check if reference existsifrepo_mgr.ref_exists("v1.0.0"):print("Tag v1.0.0 exists")# Get reference typeref_type=repo_mgr.get_ref_type("develop")print(f"'develop' is a {ref_type}")# Output: 'develop' is a branch
# Auto-update to latest commit on branchsync:auto_update:trueupdate_interval:3600# Check every hourrepository:ref:mainfollow_ref:true# Follow branch updates
#!/bin/bash# Sync multiple branches to different directoriesbranches=("main""develop""staging")forbranchin"${branches[@]}";dogitbridgesync\--repohttps://github.com/user/repo\--local~/projects/repo-$branch\--ref$branchdone
importrandomfromgitbridgeimportGitHubAPISync# A/B test between branchesbranch=random.choice(['feature-a','feature-b'])sync=GitHubAPISync(repo_url,f"/deploy/{branch}")sync.sync(ref=branch)
# Different settings per reference typeoptimization:branches:incremental:truecache_ttl:300tags:incremental:false# Full sync for tagscache_ttl:86400# Cache tags for 24 hourscommits:incremental:falsecache_ttl:-1# Cache forever (commits don't change)
# Check if reference existsgitbridgelist-branches--repohttps://github.com/user/repo|grepxyz
# Use full reference namegitbridgesync--refrefs/heads/feature/xyz
# Enforce reference policiesALLOWED_BRANCHES=['main','develop','staging']defvalidate_ref(ref):ifrefnotinALLOWED_BRANCHES:raiseValueError(f"Branch {ref} not allowed in production")