git clone 所有分支到本地的方法

1. 克隆仓库,默认克隆下来的是master

$ git clone https://github.com/PX4/PX4-ECL.git
Cloning into 'PX4-ECL'...
remote: Enumerating objects: 10932, done.
remote: Counting objects: 100% (370/370), done.
remote: Compressing objects: 100% (180/180), done.
remote: Total 10932 (delta 224), reused 290 (delta 188), pack-reused 10562
Receiving objects: 100% (10932/10932), 26.57 MiB | 212.00 KiB/s, done.
Resolving deltas: 100% (7887/7887), done.
$ cd PX4-ECL/

2. 取所有分支并创建本地分支和远程分支的联系

执行下边这一行命令即可:

for i in `git branch -a | grep remote | grep -v HEAD | grep -v master`; do git branch --track ${i#remotes/origin/} $i; done

以下是执行的结果:

$ for i in `git branch -a | grep remote | grep -v HEAD | grep -v master`; do git branch --track ${i#remotes/origin/} $i; done
Branch 'Release_v1.10' set up to track remote branch 'Release_v1.10' from 'origin'.
Branch 'Release_v1.10.0' set up to track remote branch 'Release_v1.10.0' from 'origin'.
Branch 'Release_v1.11' set up to track remote branch 'Release_v1.11' from 'origin'.
Branch 'Release_v1.7.0' set up to track remote branch 'Release_v1.7.0' from 'origin'.
Branch 'accel-bias-divergence-debug' set up to track remote branch 'accel-bias-divergence-debug' from 'origin'.
Branch 'coverity_scan' set up to track remote branch 'coverity_scan' from 'origin'.
Branch 'dev-ekf-heading-reset-local' set up to track remote branch 'dev-ekf-heading-reset-local' from 'origin'.
Branch 'ekfOptFlowFixes' set up to track remote branch 'ekfOptFlowFixes' from 'origin'.
Branch 'flow_interface' set up to track remote branch 'flow_interface' from 'origin'.
Branch 'gnss-yaw-noise' set up to track remote branch 'gnss-yaw-noise' from 'origin'.
Branch 'gtest' set up to track remote branch 'gtest' from 'origin'.
Branch 'nomag_init' set up to track remote branch 'nomag_init' from 'origin'.
Branch 'pr-alphafilter_minor' set up to track remote branch 'pr-alphafilter_minor' from 'origin'.
Branch 'pr-covariance_partial_double' set up to track remote branch 'pr-covariance_partial_double' from 'origin'.
Branch 'pr-ecl_ekf_defines' set up to track remote branch 'pr-ecl_ekf_defines' from 'origin'.
Branch 'pr-ecl_float_t' set up to track remote branch 'pr-ecl_float_t' from 'origin'.
Branch 'pr-ekfBadImuHgtReset' set up to track remote branch 'pr-ekfBadImuHgtReset' from 'origin'.
Branch 'pr-ekfCovarianceFix' set up to track remote branch 'pr-ekfCovarianceFix' from 'origin'.
Branch 'pr-ekfSymPyDerivationConversion' set up to track remote branch 'pr-ekfSymPyDerivationConversion' from 'origin'.
Branch 'pr-ekfSymPyMagFusionAlt' set up to track remote branch 'pr-ekfSymPyMagFusionAlt' from 'origin'.
Branch 'pr-ekfYawFailDetect' set up to track remote branch 'pr-ekfYawFailDetect' from 'origin'.
Branch 'pr-ekf_buffer_allocate' set up to track remote branch 'pr-ekf_buffer_allocate' from 'origin'.
Branch 'pr-ekf_covariance_double_hacks' set up to track remote branch 'pr-ekf_covariance_double_hacks' from 'origin'.
Branch 'pr-ekf_init_no_baro' set up to track remote branch 'pr-ekf_init_no_baro' from 'origin'.
Branch 'pr-ekf_initialise_filter_baro_mag' set up to track remote branch 'pr-ekf_initialise_filter_baro_mag' from 'origin'.
Branch 'pr-ekf_output_predictor_hacks' set up to track remote branch 'pr-ekf_output_predictor_hacks' from 'origin'.
Branch 'pr-ekf_update_interval_parameter' set up to track remote branch 'pr-ekf_update_interval_parameter' from 'origin'.
Branch 'pr-ekf_vel_test_ratio' set up to track remote branch 'pr-ekf_vel_test_ratio' from 'origin'.
Branch 'pr-estimator_status_flags' set up to track remote branch 'pr-estimator_status_flags' from 'origin'.
Branch 'pr-ev_rng_aid' set up to track remote branch 'pr-ev_rng_aid' from 'origin'.
Branch 'pr-float_t' set up to track remote branch 'pr-float_t' from 'origin'.
Branch 'pr-geo_globallocal' set up to track remote branch 'pr-geo_globallocal' from 'origin'.
Branch 'pr-geo_split' set up to track remote branch 'pr-geo_split' from 'origin'.
Branch 'pr-globallocal_purge' set up to track remote branch 'pr-globallocal_purge' from 'origin'.
Branch 'pr-gps-yaw-simplification' set up to track remote branch 'pr-gps-yaw-simplification' from 'origin'.
Branch 'pr-indoor_mag_hacks' set up to track remote branch 'pr-indoor_mag_hacks' from 'origin'.
Branch 'pr-l1-velocity-control' set up to track remote branch 'pr-l1-velocity-control' from 'origin'.
Branch 'pr-l1_updates' set up to track remote branch 'pr-l1_updates' from 'origin'.
Branch 'pr-mag-fusion-restart' set up to track remote branch 'pr-mag-fusion-restart' from 'origin'.
Branch 'pr-matrix_init' set up to track remote branch 'pr-matrix_init' from 'origin'.
Branch 'pr-namespace' set up to track remote branch 'pr-namespace' from 'origin'.
Branch 'pr-of-control-improvements' set up to track remote branch 'pr-of-control-improvements' from 'origin'.
Branch 'pr-rng_aid_hacks' set up to track remote branch 'pr-rng_aid_hacks' from 'origin'.
Branch 'pr-rng_aid_landed' set up to track remote branch 'pr-rng_aid_landed' from 'origin'.
Branch 'pr-tecs_throttle' set up to track remote branch 'pr-tecs_throttle' from 'origin'.
Branch 'pr-tecs_vz' set up to track remote branch 'pr-tecs_vz' from 'origin'.
Branch 'pr-terrain-fusion-cleanup' set up to track remote branch 'pr-terrain-fusion-cleanup' from 'origin'.
Branch 'pr-update_geo_lookup' set up to track remote branch 'pr-update_geo_lookup' from 'origin'.
Branch 'pr-wind_cov_init' set up to track remote branch 'pr-wind_cov_init' from 'origin'.
Branch 'refactor_unit_test' set up to track remote branch 'refactor_unit_test' from 'origin'.
Branch 'stable-coverage' set up to track remote branch 'stable-coverage' from 'origin'.
Branch 'synthetic_mag' set up to track remote branch 'synthetic_mag' from 'origin'.
Branch 'test-terrain-est-ground' set up to track remote branch 'test-terrain-est-ground' from 'origin'.
Branch 'variable_initializations' set up to track remote branch 'variable_initializations' from 'origin'.
Branch 'variadic_KHP_computation' set up to track remote branch 'variadic_KHP_computation' from 'origin'.

查看一下是否已经成功:

$ git branch
  Release_v1.10
  Release_v1.10.0
  Release_v1.11
  Release_v1.7.0
  accel-bias-divergence-debug
  coverity_scan
  dev-ekf-heading-reset-local
  ekfOptFlowFixes
  flow_interface
  gnss-yaw-noise
  gtest
* master
  nomag_init
  pr-alphafilter_minor
  pr-covariance_partial_double
  pr-ecl_ekf_defines
  pr-ecl_float_t
  pr-ekfBadImuHgtReset
  pr-ekfCovarianceFix
  pr-ekfSymPyDerivationConversion
  pr-ekfSymPyMagFusionAlt
  pr-ekfYawFailDetect
  pr-ekf_buffer_allocate
  pr-ekf_covariance_double_hacks
  pr-ekf_init_no_baro
  pr-ekf_initialise_filter_baro_mag
  pr-ekf_output_predictor_hacks
  pr-ekf_update_interval_parameter
  pr-ekf_vel_test_ratio
  pr-estimator_status_flags
  pr-ev_rng_aid
  pr-float_t
  pr-geo_globallocal
  pr-geo_split
  pr-globallocal_purge
  pr-gps-yaw-simplification
  pr-indoor_mag_hacks
  pr-l1-velocity-control
  pr-l1_updates
  pr-mag-fusion-restart
  pr-matrix_init
  pr-namespace
  pr-of-control-improvements
  pr-rng_aid_hacks
  pr-rng_aid_landed
  pr-tecs_throttle
  pr-tecs_vz
  pr-terrain-fusion-cleanup
  pr-update_geo_lookup
  pr-wind_cov_init
  refactor_unit_test
  stable-coverage
  synthetic_mag
  test-terrain-est-ground
  variable_initializations
  variadic_KHP_computation

3. 最后一步将所有分支更新到最新状态

git fetch --all && git pull --all
Fetching origin
Fetching origin
Already up to date.

你可能感兴趣的:(Linux系统相关,git,github)