Sourcetree Install Mac

  



Dec 15, 2020 You can use rosseta to use latest sourcetree. Check the security options to unlock the App after the first use. I'd recommend to use homebrew to install Sourcetree, git and Hg. Brew install git git-lfs git-flow hg sourcetree. Sourcetree most definitely is not malicious. It interacts with your Git repositories and visualizes and manages your repositories through Sourcetree’s simple Git GUI. It is a Free Git client that is compatible with both Mac OS 10 and Windows 10. Make sure you have downloaded the latest version of SourceTree for Mac.

In this section, we will discuss the available 'undo' Git strategies and commands. It is first important to note that Git does not have a traditional 'undo' system like those found in a word processing application. It will be beneficial to refrain from mapping Git operations to any traditional 'undo' mental model. Additionally, Git has its own nomenclature for 'undo' operations that it is best to leverage in a discussion. This nomenclature includes terms like reset, revert, checkout, clean, and more.

A fun metaphor is to think of Git as a timeline management utility. Commits are snapshots of a point in time or points of interest along the timeline of a project's history. Additionally, multiple timelines can be managed through the use of branches. When 'undoing' in Git, you are usually moving back in time, or to another timeline where mistakes didn't happen.

This tutorial provides all of the necessary skills to work with previous revisions of a software project. First, it shows you how to explore old commits, then it explains the difference between reverting public commits in the project history vs. resetting unpublished changes on your local machine.

Finding what is lost: Reviewing old commits

Sourcetree Install Mac

The whole idea behind any version control system is to store “safe” copies of a project so that you never have to worry about irreparably breaking your code base. Once you’ve built up a project history of commits, you can review and revisit any commit in the history. One of the best utilities for reviewing the history of a Git repository is the git log command. In the example below, we use git log to get a list of the latest commits to a popular open-source graphics library.

Each commit has a unique SHA-1 identifying hash. These IDs are used to travel through the committed timeline and revisit commits. By default, git log will only show commits for the currently selected branch. It is entirely possible that the commit you're looking for is on another branch. You can view all commits across all branches by executing git log --branches=*. The command git branch is used to view and visit other branches. Invoking the command, git branch -a will return a list of all known branch names. One of these branch names can then be logged using git log .

When you have found a commit reference to the point in history you want to visit, you can utilize the git checkout command to visit that commit. Git checkout is an easy way to “load” any of these saved snapshots onto your development machine. During the normal course of development, the HEAD usually points to master or some other local branch, but when you check out a previous commit, HEAD no longer points to a branch—it points directly to a commit. This is called a “detached HEAD” state, and it can be visualized as the following:

Checking out an old file does not move the HEAD pointer. It remains on the same branch and same commit, avoiding a 'detached head' state. You can then commit the old version of the file in a new snapshot as you would any other changes. So, in effect, this usage of git checkout on a file, serves as a way to revert back to an old version of an individual file. For more information on these two modes visit the git checkout page

Viewing an old revision

This example assumes that you’ve started developing a crazy experiment, but you’re not sure if you want to keep it or not. To help you decide, you want to take a look at the state of the project before you started your experiment. First, you’ll need to find the ID of the revision you want to see.

Let’s say your project history looks something like the following:

Undoing a committed snapshot

There are technically several different strategies to 'undo' a commit. The following examples will assume we have a commit history that looks like:

We will focus on undoing the 872fa7e Try something crazy commit. Maybe things got a little too crazy.

How to undo a commit with git checkout

Using the git checkout command we can checkout the previous commit, a1e8fb5, putting the repository in a state before the crazy commit happened. Checking out a specific commit will put the repo in a 'detached HEAD' state. This means you are no longer working on any branch. In a detached state, any new commits you make will be orphaned when you change branches back to an established branch. Orphaned commits are up for deletion by Git's garbage collector. The garbage collector runs on a configured interval and permanently destroys orphaned commits. To prevent orphaned commits from being garbage collected, we need to ensure we are on a branch.

From the detached HEAD state, we can execute git checkout -b new_branch_without_crazy_commit. This will create a new branch named new_branch_without_crazy_commit and switch to that state. The repo is now on a new history timeline in which the 872fa7e commit no longer exists. At this point, we can continue work on this new branch in which the 872fa7e commit no longer exists and consider it 'undone'. Unfortunately, if you need the previous branch, maybe it was your master branch, this undo strategy is not appropriate. Let's look at some other 'undo' strategies. For more information and examples review our in-depth git checkout discussion.

How to undo a public commit with git revert

Let's assume we are back to our original commit history example. The history that includes the 872fa7e commit. This time let's try a revert 'undo'. If we execute git revert HEAD, Git will create a new commit with the inverse of the last commit. This adds a new commit to the current branch history and now makes it look like:

At this point, we have again technically 'undone' the 872fa7e commit. Although 872fa7e still exists in the history, the new e2f9a78 commit is an inverse of the changes in 872fa7e. Unlike our previous checkout strategy, we can continue using the same branch. This solution is a satisfactory undo. This is the ideal 'undo' method for working with public shared repositories. If you have requirements of keeping a curated and minimal Git history this strategy may not be satisfactory.

How to undo a commit with git reset

Undoing the last commit

Sourcetree Install Mac

In the previous section, we discussed different strategies for undoing commits. These strategies are all applicable to the most recent commit as well. In some cases though, you might not need to remove or reset the last commit. Maybe it was just made prematurely. In this case you can amend the most recent commit. Once you have made more changes in the working directory and staged them for commit by using git add, you can execute git commit --amend. This will have Git open the configured system editor and let you modify the last commit message. The new changes will be added to the amended commit.

Undoing uncommitted changes

Before changes are committed to the repository history, they live in the staging index and the working directory. You may need to undo changes within these two areas. The staging index and working directory are internal Git state management mechanisms. For more detailed information on how these two mechanisms operate, visit the git reset page which explores them in depth.

The working directory

The working directory is generally in sync with the local file system. To undo changes in the working directory you can edit files like you normally would using your favorite editor. Git has a couple utilities that help manage the working directory. There is the git clean command which is a convenience utility for undoing changes to the working directory. Additionally, git reset can be invoked with the --mixed or --hard options and will apply a reset to the working directory.

The staging index

The git add command is used to add changes to the staging index. Git reset is primarily used to undo the staging index changes. A --mixed reset will move any pending changes from the staging index back into the working directory.

Undoing public changes

Sourcetree Install Mac

When working on a team with remote repositories, extra consideration needs to be made when undoing changes. Git reset should generally be considered a 'local' undo method. A reset should be used when undoing changes to a private branch. This safely isolates the removal of commits from other branches that may be in use by other developers. Problems arise when a reset is executed on a shared branch and that branch is then pushed remotely with git push. Git will block the push in this scenario complaining that the branch being pushed is out of date from the remote branch as it is missing commits.

Install Sourcetree Windows

The preferred method of undoing shared history is git revert. A revert is safer than a reset because it will not remove any commits from a shared history. A revert will retain the commits you want to undo and create a new commit that inverts the undesired commit. This method is safer for shared remote collaboration because a remote developer can then pull the branch and receive the new revert commit which undoes the undesired commit.

Summary

Next up:

Git Clean

Start next tutorial

Install Git on Mac OS X

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:

Mac install sourcetree
  1. Download the latest Git for Mac installer.

  2. Follow the prompts to install Git.

  3. Open a terminal and verify the installation was successful by typing git --version:

  4. 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:

  5. (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:

  1. Open your terminal and install Git using Homebrew:

  2. Verify the installation was successful by typing which git --version:

  3. 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:

  4. (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:

  1. Open your terminal and update MacPorts:

  2. Search for the latest available Git ports and variants:

  3. Install Git with bash completion, the OS X keychain helper, and the docs:

  4. 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:

  5. (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.

  1. 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.

  2. Use curl to download git-credential-osxkeychain (or download it via your browser) and move it to /usr/local/bin:

  3. Make the file an executable:

  4. 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 Won't Install Mac

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:

  1. From your terminal install XCode's Command Line Tools (if you haven't already):

  2. Install Homebrew.

  3. Using Homebrew, install openssl:

  4. Clone the Git source (or if you don't yet have a version of Git installed, download and extract it):

  5. To build Git run make with the following flags:

Install Git on Windows

Git for Windows stand-alone installer

  1. Download the latest Git for Windows installer.

  2. 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.

  3. Open a Command Prompt (or Git Bash if during installation you elected not to use Git from the Windows Command Prompt).

  4. 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:

  5. 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:

  1. From your shell, install Git using apt-get:

  2. Verify the installation was successful by typing git --version:

  3. 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:

Fedora (dnf/yum)

Git packages are available via both yum and dnf:

Sourcetree install mac software
  1. From your shell, install Git using dnf (or yum, on older versions of Fedora):

    or

  2. Verify the installation was successful by typing git --version:

  3. 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:

  1. From your shell, install the necessary dependencies using apt-get:

  2. Clone the Git source (or if you don't yet have a version of Git installed, download and extract it):

  3. To build Git and install it under /usr, run make:

Fedora

Git requires the several dependencies to build on Linux. These are available via both yum and dnf:

  1. 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:

  2. Symlink docbook2X to the filename that the Git build expects:

  3. Clone the Git source (or if you don't yet have a version of Git installed, download and extract it):

  4. To build Git and install it under /usr, run make:

Next up:

Setting up a repository

Start next tutorial