Install Git on Mac OS X
Apt-get install git-flow. On Mac OS use the following command: brew install git-flow-avh. For more information on the installation of Gitflow, visit Gitflow cheat sheet by Daniel Kummer. Practical Usage of Gitflow. I am using Mac Os, and I have already installed Gitflow, in order for us to get started. I will create a folder on my desktop. Install Git on Windows Git for Windows stand-alone installer Download the latest Git for Windows installer. When you've successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation. The default options are pretty sensible for most users.
There are several ways to install Git on a Mac. In fact, if you've installed XCode (or it's Command Line Tools), Git may already be installed. To find out, open a terminal and enter git --version
.
Apple actually maintain and ship their own fork of Git, but it tends to lag behind mainstream Git by several major versions. You may want to install a newer version of Git using one of the methods below:
Git for Mac Installer
The easiest way to install Git on a Mac is via the stand-alone installer:
Download the latest Git for Mac installer.
Follow the prompts to install Git.
Open a terminal and verify the installation was successful by typing
git --version
:Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
(Optional) To make Git remember your username and password when working with HTTPS repositories, configure the git-credential-osxkeychain helper.
Install Git with Homebrew
If you have installed Homebrew to manage packages on OS X, you can follow these instructions to install Git:
Open your terminal and install Git using Homebrew:
Verify the installation was successful by typing which
git --version
:Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
(Optional) To make Git remember your username and password when working with HTTPS repositories, install the git-credential-osxkeychain helper.
Install Git with MacPorts
If you have installed MacPorts to manage packages on OS X, you can follow these instructions to install Git:
Windows Install Git Flow
Open your terminal and update MacPorts:
Search for the latest available Git ports and variants:
Install Git with bash completion, the OS X keychain helper, and the docs:
Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
(Optional) To make Git remember your username and password when working with HTTPS repositories, configure the git-credential-osxkeychain helper.
Install the git-credential-osxkeychain helper
Bitbucket supports pushing and pulling your Git repositories over both SSH and HTTPS. To work with a private repository over HTTPS, you must supply a username and password each time you push or pull. The git-credential-osxkeychain helper allows you to cache your username and password in the OSX keychain, so you don't have to retype it each time.
If you followed the MacPorts or Homebrew instructions above, the helper should already be installed. Otherwise you'll need to download and install it. Open a terminal window and check:
If you receive a usage statement, skip to step 4. If the helper is not installed, go to step 2.
Use curl to download git-credential-osxkeychain (or download it via your browser) and move it to
/usr/local/bin
:Make the file an executable:
Configure git to use the osxkeychain credential helper.
The next time Git prompts you for a username and password, it will cache them in your keychain for future use.
Install Git with Atlassian Sourcetree
Sourcetree, a free visual Git client for Mac, comes with its own bundled version of Git. You can download Sourcetree here.
To learn how to use Git with Sourcetree (and how to host your Git repositories on Bitbucket) you can follow our comprehensive Git tutorial with Bitbucket and Sourcetree.
Build Git from source on OS X
Building Git can be a little tricky on Mac due to certain libraries moving around between OS X releases. On El Capitan (OS X 10.11), follow these instructions to build Git:
Windows Install Git Cli
From your terminal install XCode's Command Line Tools (if you haven't already):
Install Homebrew.
Using Homebrew, install openssl:
Clone the Git source (or if you don't yet have a version of Git installed, download and extract it):
To build Git run make with the following flags:
Install Git on Windows
Git for Windows stand-alone installer
Download the latest Git for Windows installer.
When you've successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation. The default options are pretty sensible for most users.
Open a Command Prompt (or Git Bash if during installation you elected not to use Git from the Windows Command Prompt).
Run the following commands to configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
Optional: Install the Git credential helper on Windows
Bitbucket supports pushing and pulling over HTTP to your remote Git repositories on Bitbucket. Every time you interact with the remote repository, you must supply a username/password combination. You can store these credentials, instead of supplying the combination every time, with the Git Credential Manager for Windows.
Install Git with Atlassian Sourcetree
Sourcetree, a free visual Git client for Windows, comes with its own bundled version of Git. You can download Sourcetree here.
To learn how to use Git with Sourcetree (and how to host your Git repositories on Bitbucket) you can follow our comprehensive Git tutorial with Bitbucket and Sourcetree.
Install Git on Linux
Debian / Ubuntu (apt-get)
Git packages are available via apt:
From your shell, install Git using apt-get:
Verify the installation was successful by typing
git --version
:Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
Install Git Flow Windows 7
Fedora (dnf/yum)
Git packages are available via both yum and dnf:
From your shell, install Git using dnf (or yum, on older versions of Fedora):
or
Verify the installation was successful by typing
git --version
:Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create
Build Git from source on Linux
Debian / Ubuntu
Git requires the several dependencies to build on Linux. These are available via apt:
From your shell, install the necessary dependencies using apt-get:
Clone the Git source (or if you don't yet have a version of Git installed, download and extract it):
To build Git and install it under
/usr
, runmake
:
Fedora
Git requires the several dependencies to build on Linux. These are available via both yum and dnf:
From your shell, install the necessary build dependencies using dnf (or yum, on older versions of Fedora):
or using yum. For yum, you may need to install the Extra Packages for Enterprise Linux (EPEL) repository first:
Symlink docbook2X to the filename that the Git build expects:
Clone the Git source (or if you don't yet have a version of Git installed, download and extract it):
To build Git and install it under
/usr
, runmake
:
Next up:
Setting up a repository
Start next tutorialVincent Driessen’s 'git flow' branching model is a git branching and release management workflow that helps developers keep track of features, hotfixes and releases in bigger software projects. This workflow has lot of commands to type and remember, so there’s also the git-flow library of git subcommands to help automate some parts of the flow to make working with it easier.
After installing git-flow (brew install git-flow
), you can start using git-flow in your repository by using it’s init
command. You can use it in existing projects, but let’s start a new repository:
git-flow is a wrapper around existing git commands, so the init
command doesn’t change anything in your repository other than creating branches for you. If you don’t want to use git-flow anymore, there’s nothing to change or remove, you just stop using the git-flow commands.
If you run git branch
after setting up, you’ll notice that you switched from the master branch to a new one named develop
.
The develop
branch the default branch where most of the work will happen, and the master
branch keeps track of production-ready code.
Feature branches
git-flow makes it easy to work on multiple features at the same time by using feature branches. To start one, use feature start
with the name of your new feature (in this case, “authentication”):
A feature branch was created and you’re automatically switched to it. Implement your feature in this branch while using git like you normally would. When you’re finished, use feature finish
:
Your feature branch will be merged and you’re taken back to your develop
branch. Internally, git-flow used git merge --no-ff feature/authentication
to make sure you don’t lose any historical information about your feature branch before it is removed.
Versioned releases
If you need tagged and versioned releases, you can use git-flow’s release branches to start a new branch when you’re ready to deploy a new version to production.
Like everything else in git-flow, you don’t have to use release branches if you don’t want to. Prefer to manually git merge --no-ff develop
into master without tagging? No problem.However, if you’re working on a versioned API or library, release branches might be really useful, and they work exactly like you’d expect:
Bump the version number and do everything that’s required to release your project in the release branch. I personally wouldn’t do any last minute fixes, but if you do, git-flow will make sure everything is correctly merged into both master
and develop
.Then, finish the release:
Boom. git-flow pulls from origin, merges the release branch into master, tags the release and back-merges everything back into develop before removing the release branch.
You’re still on master, so you can deploy before going back to your develop
branch, which git-flow made sure to update with the release changes in master
.
Hotfixing production code
Because you keep your master
branch always in sync with the code that’s on production, you’ll be able to quickly fix any issues on production.
For example, if your assets aren’t loading on production, you’d roll back your deploy and start a hotfix branch:
Hotfix branches are a lot like release branches, except they’re based on master instead of develop. You’re automatically switched to the new hotfix branch so you can start fixing the issue and bumping the minor version number.When you’re done, hotfix finish
:
Like when finishing a release branch, the hotfix branch gets merged into both master
and develop
. The release is tagged and the hotfix branch is removed.
Why aren’t you using git-flow?
If you’re not doing versioned releases, Vincent’s git workflow and the git-flow library might not be a right fit for you. However, if you work on a project that’s semantically versioned, like a Rubygem or a versioned API, git-flow will give you a couple of simple commands that will do a lot of work under the hood, making working on features, pushing new releases and hotfixing bugs a lot easier. Well, at least on the git side.