一. 安装
使用brew安装GIT
MacBook-Pro:~ $ brew install git Updating Homebrew... ==> Auto-updated Homebrew! Updated 1 tap (homebrew/core). ==> New Formulae akamai dep lean pcb ampl-mp dlib libbitcoin pcl apibuilder-cli docfx libbitcoin-explorer pdfsandwich apng2gif erlang@17 libmatio pony-stable armadillo flann libpq pumba arpack frugal libtrng qhull azure-cli@1 geth libxlsxwriter qrupdate bash-snippets [email protected] liquid-dsp root@5 bento4 glpk llvm@4 s-nail bettercap gmsh marathon-swift [email protected] braid gmt maxima scalapack brainfuck [email protected] metis sccache ceres-solver gomplate mimic snapcraft cfitsio goose mujs stubby clblas gopass nco suite-sparse clfft gromacs ncview sundials clinfo [email protected] netcdf superlu clojure http-server nlopt telnet cminpack hwloc octave trash-cli configen hypre openblas veclibfort cppad igraph opencv@2 voro++ credstash inetutils ott vtk cryfs json-table packmol wxmaxima datamash jupyter payara xtensor ==> Updated Formulae abcm2ps gmime node@6 abcmidi gnome-builder nodeenv ace gnome-recipes nodenv acmetool gnu-chess nomad acpica gnupg notmuch activemq gnupg-pkcs11-scd nsd activemq-cpp [email protected] nspr advancecomp gnuplot nss aespipe gnuplot@4 numpy afl-fuzz gnustep-make nuxeo afsctool gnutls nvm agda go nzbget agedu goad ola alexjs gobject-introspection ✔ oniguruma algernon godep onscripter allure goenv open-scene-graph alot gofabric8 openal-soft amazon-ecs-cli gom openclonk ammonite-repl goocanvas opencoarrays angular-cli goofys opencsg anjuta google-benchmark opendetex ansible google-java-format openforti ansible-lint googler openjpeg [email protected] gource openmsx ansifilter gphoto2 openrct2 apache-arrow gpp openrtsp apache-flink gpsbabel opensc apache-opennlp gpsim openshift-cli apache-zeppelin gputils openslide apktool grace openvdb app-engine-go-64 gradle ✔ opusfile app-engine-java grafana orc app-engine-python grails orientdb apr grakn osm-pbf apr-util graphicsmagick osm2pgrouting aptly grib-api osm2pgsql arangodb groonga osmium-tool argyll-cms grpc osquery arx-libertatis grunt-completion osrm-backend ascii gsettings-desktop-schemas overmind asdf gsmartcontrol oysttyer aspell gsoap p11-kit assimp gspell packer at-spi2-atk gst-plugins-bad packetbeat at-spi2-core gst-plugins-good paket atk gst-plugins-ugly pam_yubico atlassian-cli gtk+3 pandoc ats2-postiats gtk-doc pandoc-citeproc audacious gtk-gnutella pandoc-crossref augeas gtkmm3 pango autopano-sift-c gtksourceview3 parallel avfs gucharmap passenger avro-c gupnp-tools pazpar2 avro-cpp gwenhywfar pc6001vx avro-tools gws pcb2gcode aws-elasticbeanstalk gwyddion pcre2 aws-sdk-cpp hadoop pdf2htmlex aws-shell hana pdftoedn awscli haproxy pdftoipe awslogs harfbuzz ✔ percona-server axel hashcat percona-server-mongodb azure-cli haskell-stack [email protected] babl haste-client [email protected] bacula-fd haxe percona-toolkit bandcamp-dl hdf5 percona-xtrabackup baobab heroku pgbadger baresip hevea pgcli bartycrouch hexedit pgformatter basex hfstospell pgloader bash-completion hg-fast-export pgrouting bash-git-prompt hicolor-icon-theme pianobar bashdb highlight pick bazel hivemind picoc bcpp hledger pike beecrypt homebank pilosa bibtexconv hspell pioneer bibutils htmldoc pjproject bigloo http_load planck binaryen httpflow plantuml bind hugo platformio binutils hunspell plowshare bit hydra plplot bitcoin hyper pngcrush bitrise hyperscan pngquant blastem i2p poco blockhash i3 podofo bltool i3status points2grid bmake iamy ponscripter-sekai bmon ibex ponyc bnd icbirc poppler bonnie++ ice postgresql boost icecream [email protected] boost-bcp icoutils [email protected] boost-mpi icu4c ✔ postgrest boost-python idris potrace boot-clj imagemagick povray botan imagemagick@6 ppsspp brew-gem imageworsener pqiv brotli imlib2 pre-commit btfs immortal presto buku infer primesieve byobu influxdb protobuf cabal-install [email protected] protobuf-c caddy innoextract protobuf-swift cake insect psqlodbc camlp5 instead pulseaudio cargo-completion io pwgen carthage ios-deploy pwntools cassandra ios-sim py2cairo [email protected] ios-webkit-debug-proxy py3cairo castxml iozone pybind11 catimg ipbt pyenv cc65 ipython pyenv-virtualenv ccextractor ipython@5 pygobject3 cclive ircd-hybrid pyinvoke ccm ircii qbs certbot ired qcli certstrap isc-dhcp qemu ceylon iso-codes qpdf cgal isync qrencode cgrep itex2mml quantlib chakra ivykis r cheat jasper rabbitmq checkbashisms jbig2enc rakudo-star checkstyle jboss-forge rancher-cli chipmunk jena rclone chordii jenkins re2 chromedriver jenkins-job-builder re2c chronograf jenkins-lts rebar@3 cimg jetty recon-ng citus jetty-runner redex clasp jfrog-cli-go redis clhep jhipster [email protected] cli53 jmxtrans remake clib jp2a residualvm cloc jpeg ✔ restund clojurescript jpeg-turbo rethinkdb closure-compiler jpeginfo rgbds clutter-gtk jpegoptim rhash cmake jruby rhino cmark jsdoc3 riak cmark-gfm json-c riemann-client cockatrice json-fortran ripgrep cockroach jsoncpp rlvm cocoapods jsonschema2pojo rocksdb coffeescript juju rom-tools collector-sidecar julius roswell commandbox jvgrep rt-audio compcert kafka rtags conan kapacitor rtmidi confuse khal rtv conjure-up kibana ruby ✔ consul kitchen-sync ruby-build consul-backinator klavaro [email protected] consul-template knot [email protected] convmv knot-resolver rust convox kobalt rustup-init corebird kompose rxvt-unicode corectl kops s-search coreutils kotlin s6 couchdb ktoblzcheck saldl cppcheck kube-aws saltstack cputhrottle kubernetes-cli sane-backends crash kubernetes-helm saxon creduce languagetool sbcl cromwell latexila sbt crosstool-ng launch4j scala crowdin launchdns scalaenv cryptol lbdb scalariform crystal-icr lcdproc scamper crystal-lang ldc scipy cucumber-cpp le scons curl lean-cli scour cython ledger scummvm dar legit sdb dasht leptonica sdcv dateutils lftp sdl2_image dbhash libagar sdl_image dbt libav selenium-server-standalone dbus libbpg sfcgal dcd libcdr sfml dcm2niix libcds s-libev dcmtk libchamplain shairport-sync dcos-cli libcoap shared-mime-info dcraw libcouchbase sjk ddar libdap skinny debianutils libdiscid slackcat deis libdsk sleuthkit dependency-check libebml snakemake depqbf liberasurecode snap-telemetry devil libfabric snappy dfc libfaketime sngrep dhall-json libfixbuf socat diff-pdf libflowmanager softhsm diffoscope libfreenect sonarqube digdag libftdi sops django-completion libgaiagraphics source-highlight djvulibre libgcrypt sourcekitten dmd libgeotiff sourcery dmtx-utils libgit2-glib spandsp dnsmasq libgphoto2 spdlog docker libgsm sphinx-doc docker-cloud libgweather spim docker-completion libgxps sqlcipher docker-compose libhdhomerun sqldiff docker-compose-completion libhttpseverywhere sqlite ✔ docker-credential-helper libinfinity sqlite-analyzer docker-machine-driver-vultr libjson-rpc-cpp sqlmap docker-machine-parallels liblcf squid docker-swarm liblo ssdeep docutils ✔ liblockfile sshfs double-conversion libmagic sslyze dovecot libmowgli statik druid libmpdclient stella dsh libmspub stgit dspdfviewer libmwaw streamlink dtc libngspice strongswan dterm libosinfo subnetcalc dub libosmium subversion duck libpano supersonic duo_unix libpeas supertux duplicity libphonenumber supervisor duply libpng ✔ suricata dvdauthor libprotoident svg2pdf dvm libpst svg2png dwarfutils libqalculate swiftformat dwdiff libquicktime swiftgen dynamips librasterlite swiftlint e2fsprogs libraw swimat easyrpg-player libre syncthing efl libsodium syntaxerl eg libsoup sysbench ejabberd libspectrum sysdig elasticsearch libstfl szip [email protected] libsvg-cairo t1utils elixir libtensorflow talloc elvish libtiff ✔ tarsnap emacs libtommath tarsnap-gui emacs-clang-complete-async libtorrent-rasterbar taylor embulk libtrace tbb emp libu2f-host tbox emscripten libuninameslist tcl-tk encfs libuv tcpdump entr libuvc tectonic epeg libvirt tee-clc eprover libvisio teensy_loader_cli erlang libvoikko telegraf etcd libwbxml teleport etsh libwmf termius evince libwps terraform exact-image libxkbcommon terraform-docs exempi libxml2 terragrunt exim libzip testssl expat lightning texinfo exploitdb linkerd texmath eye-d3 little-cms tfenv faas-cli little-cms2 ✔ tgui fabio lldpd the_silver_searcher fabric llnode thefuck fail2ban llvm tiff2png fakeroot log4cpp tika fatsort logstalgia tile38 fb-client logstash timedog fd logtalk tinc fdroidserver luaver tippecanoe feh lumo tmuxinator-completion ffe lxc todolist ffmpeg ✔ lynis todoman ffmpegthumbnailer lz4 tokei fibjs lzlib tomcat ficy lzop tomcat-native file-formula m-cli tomcat@6 file-roller macos tomcat@7 filebeat macvim tor fio magic-wormhole trace2html firebase-cli makensis trafficserver fits makeself trafshow fizmo mal4s transcrypt fizsh mame translate-toolkit flactag mandoc treefrog flake8 mapcrafter tsung flatcc mapnik ttfautohint flawfinder mapserver tth flow mariadb twarc flowgrind [email protected] twoping fltk [email protected] typescript fluent-bit mbedtls ufoai fobis mdp ufraw folly media-info uhd fontconfig ✔ mediaconch unbound fontforge mednafen unibilium fonttools memcached unrar forego menhir upscaledb format-udf mercurial urh fossil meson urweb fox metabase vagrant-completion freeciv metaproxy vala freeipmi metricbeat valabind freeling mgba varnish freeswitch micro varnish@4 freetds micropython vault freetype ✔ mikutter vdirsyncer freexl minetest vice fs-uae mingw-w64 vim ✔ fstar minidlna [email protected] fswatch minimal-racket vimpc fuse-emulator minio vips fuse-zip minizinc vncsnapshot fwknop mitmproxy vnu fwup mjpegtools volatility fzf mksh voldemort gabedit mkvtoolnix vowpal-wabbit galen mldonkey w3m gammaray mm-common wabt gandi.cli mmark watchexec ganglia mobile-shell watchman gauge monax watson gcc monetdb webdis gcsfuse mongo-c-driver weboob gd mongo-cxx-driver webp gdal mongo-orchestration webpack gdb mongodb wesnoth gdk-pixbuf mongoose whois gdl mono-libgdiplus widelands gearman mpc wimlib geckodriver mpd wine gedit mpdas winetricks geeqie mpdscribble wiredtiger gegl mpfr wireguard-tools geocode-glib mpg123 wireshark geos mpv woboq_codebrowser geoserver mpw wolfssl get-flash-videos mscgen wpcli-completion get_iplayer msgpack wpscan getdns msitools wxmac ghc mspdebug x11vnc ghostscript mutt x264 ✔ ghq mycli xapian gifsicle mypy xctool git mysql ✔ xmake git-annex mysql-cluster xmoto git-flow-avh mysql-connector-c xorriso git-fresh mysql-sandbox xplanet git-lfs [email protected] xrootd git-quick-stats [email protected] xsane git-town nagios xsv gitbucket nano yadm gitg nanopb-generator yarn github-markdown-toc nativefier yaz gitlab-ci-multi-runner ncmpc yle-dl gjs ncmpcpp you-get gjstest nestopia-ue youtube-dl gl2ps netpbm zabbix glade newsbeuter zanata-client glassfish nghttp2 zbackup glew ngspice zbar glib ✔ nim zebra glib-networking nmap zimg glibmm nnn zorba glm no-more-secrets zsh gloox node zsh-syntax-highlighting gmic node-build zstd ==> Renamed Formulae fbida -> exiftran opencv3 -> opencv gmt4 -> gmt@4 root6 -> root gnome-icon-theme -> adwaita-icon-theme [email protected] -> [email protected] gtef -> tepl transfig -> fig2dev ==> Deleted Formulae abi-compliance-checker jpeg@9 mapnik@2 szl gh [email protected] [email protected] go-gui kes [email protected] ==> Downloading https://homebrew.bintray.com/bottles/git-2.14.1.sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring git-2.14.1.sierra.bottle.tar.gz ==> Caveats Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completions and functions have been installed to: /usr/local/share/zsh/site-functions Emacs Lisp files have been installed to: /usr/local/share/emacs/site-lisp/git ==> Summary �� /usr/local/Cellar/git/2.14.1: 1,485 files, 33.5MB MacBook-Pro:~ $ git --version git version 2.14.1 MacBook-Pro:~ $
更新GIT
MacBook-Pro:~ $ git clone git://git.kernel.org/pub/scm/git/git.git Cloning into 'git'... remote: Counting objects: 230660, done. remote: Compressing objects: 100% (56775/56775), done. remote: Total 230660 (delta 172034), reused 230254 (delta 171743) Receiving objects: 100% (230660/230660), 50.50 MiB | 137.00 KiB/s, done. Resolving deltas: 100% (172034/172034), done. MacBook-Pro:~ $
二. 设置GIT环境
GIT使用git config工具获取和设置配置变量,这些变量控制GIT操作的方方面面,它们被保存在3个不同的地方:
1. /etc/gitconfig 文件:保存着系统里所有用户和他们仓库的配置变量。给git config输入参数--system,可以指定从这个文件里读写配置变量。
2. ~/.gitconfig 或 ~/.config/git/config文件:保存当前用户的GIT配置变量,使用参数--global读取这个文件的配置变量。
3. config文件在当前使用的GIT仓库下(.git/config):保存当前仓库的配置变量。
设置用户名和Email地址
MacBook-Pro:~ $ git config --global user.name "XXXXX" MacBook-Pro:~ $ git config --global user.email [email protected] MacBook-Pro:~ $
设置GIT的编辑器
MacBook-Pro:~ $ git config --global core.editor vim MacBook-Pro:~ $
检查GIT设置
MacBook-Pro:~ $ git config --list credential.helper=osxkeychain user.name=XXXX [email protected] filter.lfs.clean=git-lfs clean %f filter.lfs.smudge=git-lfs smudge %f filter.lfs.required=true core.editor=vim MacBook-Pro:~ $
MacBook-Pro:~ $ git config user.name XXXXXX MacBook-Pro:~ $
三. 获取帮助
获取GIT命令的manpage
MacBook-Pro:~ $ git helpMacBook-Pro:~ $ git --help MacBook-Pro:~ $ man git-