During development of Node.JS, you may need to clone a GitHub reposity to local mac computer. A repository on GitHub is a remote repository. You can clone the repository to your mac computer in order to create a local copy and sync between the two locations. If you have locate on mac, and a regularly running updatedb, locate might be much faster: locate albatrocity grep git-version-control.markdown It uses a hashtable to fast access filenames, but can be out of date, if the database isn't updated regularly or the file is too young (typically less than one day old). Focus on what matters instead of fighting with Git. Whether you're new to Git or a seasoned user, GitHub Desktop simplifies your development workflow. Download for macOS Download for Windows (64bit) Download for macOS or Windows (msi) Download for Windows. By downloading, you agree to the Open Source Applications Terms. After you have successfully installed Git on Mac, you’ll need to provide secure communication with your Git repositories by creating and installing SSH keys. Creating SSH keys on Mac To communicate with the remote Git repository in your Beanstalk account from your Mac, you will need to generate an SSH key pair for that computer.
There is an updated version of this post for OS X 10.9. While the steps below should still work, I recommend checking out the new guide if you are running 10.9!
There are already plenty of guides that explain the particular steps of getting Git and Github going on your mac in detail. However, I had difficulty finding one that explained every step required in order with simple enough instructions for Terminal novices to follow along with autonomously.
So I decided to write one myself.
Background
I enjoy helping people become more efficient and productive, particularly when it comes to their computers and mobile devices. At a recent job, the staff design team was beginning a period of close collaboration with the front-end development team in the interest of achieving the best possible product in the shortest period of time.
However, there was a slight “problem.” The project’s codebase was exclusively managed via Git repositories on Github. Most of the designers had never worked with Git, let alone ever configured it on their workstations.
Most of the designers had some knowledge of the technologies that went into the codebase, particularly presentation layer tech like HTML and CSS. Some even knew programming languages like Javascript, PHP, and Ruby.
In an effort to unleash this previously untapped resource for a round of intense polishing and bug-fixing, I took it upon myself to write a step-by-step guide that any member of our studio could follow and be up and running with developer tools, Git, connected to Github, and ready to work on the project codebase.
This then is a slightly abbreviated1 version of the guide I distributed out to the team. Ultimately just a few days after releasing it, nearly everyone in the office — including design, production, management, and even a few devs setting up new machines — was able to at least view the latest code on their workstations.
Aside from the fact that my guide helped others quickly get through the arduous process of installation and configuration, I was happy to have it as a quick reference for myself when setting up new machines of my own. Enjoy!
Getting started
This tutorial assumes you’re using a Mac running at least OS X 10.7. If you are unsure of what OS you have, go up to the top left of your screen, click the Apple menu, and select “About This Mac.”
You’ll also need to ensure that your user account on your computer has admin privileges and that you know your account’s password.
Install the Command Line Tools for OS X
Xcode is a nearly 4GB developer suite Apple offers for free from the Mac App Store. However, for the purposes of getting Git and Github setup, you’ll only need a specific set of command line tools2 which fortunately take up much less space.
If you don’t mind the 4GB, by all means go for Xcode. Otherwise, you’ll have to go to connect.apple.com and register an Apple Developer account in order to download these tools.
Once you’ve registered, they can be found at developer.apple.com/xcode by clicking on “View downloads” and finding the appropriate command line tools for your version of OS X in the list.
- If you are on OS X 10.7.x, download The 10.7 Command Line Tools. If you are on OS X 10.8.x, download The 10.8 Command Line Tools.
- When your download finishes, go ahead and open the DMG.
- Run the Command Line Tools installer.
A note about the Terminal
The Terminal application comes pre-installed with OS X, and can be found in the Applications -> Utilities folder. You can also quickly access it using Spotlight.
The terminal has a variety of uses, but for the purposes of this tutorial we’ll be using a syntax/command set called Bash. Terminal is already configured to use this syntax.
When you enter a command and press return/enter, often times the terminal will execute it and complete the task immediately.
Sometimes it will log information in the window while it’s working, but other times you might feel like it isn’t doing anything at all.
Some of the commands later in this tutorial can take a few seconds (or minutes) to complete, so don’t type anything into the terminal window or close the terminal window until you see it present you with a fresh prompt ending in
yourusername$
.For the purposes of this tutorial, commands that I intend for you to type will be preceded with
$
, but don’t include that symbol when you enter the commands. It’s purely meant as an indicator and reference to the $
that appears in your terminal prompt.Lines that contain comments/notes from me to will be preceded with
#
and will be dimmed. Don’t type these either.Make sure to press return after typing a command before you enter the next one.
Installing Git
“Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.”
We need to install Git onto your computer. It won’t have an icon in your dock, but it can be used by the Terminal (and other applications, more on that later).
OS X comes with a fairly old version of Git pre-installed, so we’ll want to make sure that your terminal is using a more updated version.
One specific reason you’ll want to have a newer version of Git than the one that ships with OS X is to take advantage of a nice authentication feature that allows you to seamlessly interact with Github.
- Download the latest stable release of Git. It should start downloading a DMG which for some reason will include the words “Snow Leopard” in the file name…don’t worry, it works with Lion and Mountain Lion just fine.
- When it’s done downloading, open the DMG and run the package installer.Note: If you are using OS X 10.8 and haven’t already modified your security settings to allow the installation of third-party applications, you’ll need to make that adjustment3 before OS X lets you install these tools.
- Once the installer has finished, open the Terminal app and type
git --version
followed by the return key. Note that there are two dashes, not one. - The terminal should report back with your currently installed Git version.If it reports a Git version that matches the version number marked on the DMG you downloaded (as of writing, this would be 1.8.1.3) proceed to Configuring Git identification, otherwise you’ll need to execute the following:
Configuring Git identification
Now let’s configure your Git installation so other folks who might be working on projects with you know who’s doing all of the great work coming from your computer.
Setup Github
“GitHub is a web-based hosting service for software development projects that use the Git revision control system.”
Go to Github.com and create a free account if you haven’t already.
Github Keychain Helper
To save time in the future, we’ll install a utility that will allow your computer to authenticate with Github automatically instead of having to enter your username/password during each session.
First, check if the helper is installed by typing
git credential-osxkeychain
into the terminal.If the helper is installed, the terminal will give you instructions on how to use it:
If see the above message, you are now able to access Git repositories using the HTTPS method. There’s a very good chance that this is the only method you will need to access repositories and you can move on to my final notes.
If you don’t have the keychain helper already installed, you’ll see this instead:
To install the keychain helper, execute the following commands:
Once again, if the helper has been installed successfully, the terminal will give you instructions on how to use it:
If see the above message, you are now able to access Git repositories using the HTTPS method. There’s a very good chance that this is the only method you will need to access repositories and you can move on to my final notes.
If you don’t see the above message, you hit a snag along the way. Try going through the keychain helper install steps again.
Otherwise, if you have a specific reason that you need to access Git repositories using SSH, proceed to SSH Keys.
SSH Keys (optional step)
“SSH uses public-key cryptography to authenticate the remote computer and allow it to authenticate the user, if necessary. There are several ways to use SSH; one is to use automatically generated public-private key pairs to simply encrypt a network connection, and then use password authentication to log on.”
An SSH key basically lets your computer uniquely identify itself when it connects to servers. If Github is aware of the key your computer is using, you won’t have to enter your Github username/password every time you connect.
Check for pre-existing SSH keys on your computer
Let’s see if your computer has one or more keys already installed:
If you get the response “No such file or directory”, skip to Generate a new SSH Key.
Otherwise, you’ll need to backup and remove your existing SSH keys.
Backup and remove your existing SSH keys.
Generate a new SSH key
Now we’ll create a new SSH key to use with Github.
When it asks you to enter a file name in which to save the key, just press return/enter (leave the prompt blank).
You will then be asked to enter a passphrase and confirm it. Don’t make this blank, and don’t make it an easily guessable. This prevents someone from easily acquiring and using your SSH key to impersonate you. Don’t worry, you won’t have to enter this key much (if at all) after initial setup.
Press return after each time you’ve entered your selected passphrase. You won’t see the characters or bullets, the cursor will stay in the same spot as if you aren’t typing.
If you make an error entering your password one of the times, just press return and it will prompt you to try again.
Once you’ve successfully set your passphrase, the terminal will report that your key has been saved and will present you with some sweet ASCII art.
Add your SSH key to Github
In order for your computer to access Github without you having to enter your username/password all the time, Github needs to know the contents of the SSH key you just generated.
Now we’ll add your key to Github:
- Visit your account settings.
- Click Add SSH key.
- Enter a descriptive title for the computer you’re currently on, e.g. “Work iMac” into the Title field.
- Paste your key into the Key field (it has already been copied to your clipboard).
- Click Add Key.
- Enter your Github password.
Now let’s test that it all worked.
Congratulations!
Your Mac is now up and running with both Git and Github. I intend to write another post about some of the commonly used commands I always find myself looking up syntax for, as well as those that members on the team had to learn in order to effectively take part in the production process.
Recommended tools
Text Editors
If you’re just getting your feet wet with writing code, you’ll want to look into a text editor that is purpose built for that task.
My hardcore colleagues wouldn’t leave me alone if I didn’t also mention command-line editors like Vim and Emacs, but I’d recommend one of the previously listed apps for getting started.
I don’t recommend using TextEdit as it doesn’t offer syntax highlighting, and I’m personally not fond of Dreamweaver for writing code as I feel it allows its WYSIWYG mode to be used as a crutch. That said, Dreamweaver’s predecessor4 in Adobe’s product lineup was what I learned to write HTML on, so there’s that.
However with the explosion of online code teaching platforms out there (and Firebug/DOM inspector tools), I don’t see the need to use a WYSIWYG editor anymore.
Download Git Repository Mac Os
Git GUI Tools
When I first started dabbling with Git, I used the popular Tower app to manage my repositories. It has a fantastic interface and offers most of the features of the command line app.
However when we began this endeavor at my past job, the development team and I wanted to ensure that all persons with access to the codebase thought about what the actions they were going to take, and deliberately execute commands.
GUI tools are great, but they can sometimes allow disastrous things to happen with the push of a button. Additionally they can abstract away the syntax of the language/protocol they are built upon, and as a result leave users dependent on the GUI rather than knowledgeable about the underlying technology.
If you must use a GUI tool, by all means do. However in the circumstances I mentioned, it wasn’t an option we wanted to offer.
Terminal Configuration
I’ve been enjoying iTerm2 for a few small perks it offers, mainly the ability to have perfect representation of the Solarized Dark theme.
Feedback
If there are any steps/instructions I’ve written that have been outdated by newer information/technology, are simply wrong, or could be explained better please feel free to contact me on Twitter where I’m @burnedpixel.
- The stack for this project was very complicated and resulted in us using Vagrant and VirtualBox to literally get virtual instances of the dev environment going on each workstation.↩
- I had hosted the appropriate DMGs for the 10.7 and 10.8 tools on a local fileserver to speed up this step. Unfortunately the general public will have to go to Apple’s developer site, sign up for a free account, and download the tools from there.↩
- Security settings adjustment to install Git:
- Go to Apple Menu > System Preferences
- Click Security & Privacy
- Click the lock icon in the bottom left and enter your account password
- Select “Anywhere” for the “Allow applications downloaded from” setting
- Close System Preferences
- While I may have been exposed to making web pages by software like Claris Home Page and Microsoft FrontPage, I really learned to write HTML by hand from a software suite called GoLive Cyberstudio. In what has now become a familiar process, Adobe bought GoLive out so they could integrate Cyberstudio into their product lineup. In what has now also become familiar, Cyberstudio (simply rebranded as GoLive) rarely got any updates and lived a deprecated existence until it’s death nearly 10 years later.↩
When you clone an existing Git repository, or put an existing project under Git version control, IntelliJ IDEA automatically detects if Git is installed on your computer. If the IDE can't locate a Git executable, it suggests downloading it.
IntelliJ IDEA supports Git from the Windows Subsystem for Linux 2 (WSL2), which is available in Windows 10 version 2004.
If Git is not installed on Windows, IntelliJ IDEA searches for Git in WSL and uses it from there. Also, IntelliJ IDEA automatically switches to Git from WSL for projects that are opened when you use the wsl$ path.
If for some reason you need to manually configure IntelliJ IDEA to use Git from WSL, in the Settings/Preferences dialog Ctrl+Alt+S go to Version Control | Git, click the Browse icon in the Path to Git executable field and select Git from WSL via the
wsl$
path, for example, wsl$debianusrbingit
. Check out a project from a remote host (clone)
IntelliJ IDEA allows you to check out (in Git terms clone) an existing repository and create a new project based on the data you've downloaded.
- From the main menu, select VCS | Get from Version Control, or, if no project is currently opened, click Get from Version Control on the Welcome screen.
- In the Get from Version Control dialog, specify the URL of the remote repository you want to clone, or select one of the VCS hosting services on the left.If you are already logged in to the selected hosting service, completion will suggest the list of available repositories that you can clone.
- Click Clone. If you want to create a project based on the sources you have cloned, click Yes in the confirmation dialog. Git root mapping will be automatically set to the project root directory.If your project contains submodules, they will also be cloned and automatically registered as project roots.
- When you're importing or cloning the project for the first time, IntelliJ IDEA analyzes it. If the IDE detects more than one configuration (for example, Eclipse and Gradle), it prompts you to select which configuration you want to use.Select the necessary configuration and click OK.The IDE pre-configures the project according to your choice. For example, if you select Android Gradle project, IntelliJ IDEA adds the Android facet to the project during import with the tools for developing mobile applications for Android.
Put an existing project under Git version control
You can create a local Git repository based on an existing project sources.
Associate the entire project with a single Git repository
- Open the project that you want to put under Git.
- Choose Enable Version Control Integration from the VCS Operations PopupAlt+` or from the main VCS menu.
- Choose Git as the version control system and click OK.
- After VCS integration is enabled, IntelliJ IDEA will ask you whether you want to share project settings files via VCS. You can choose Always Add to synchronize project settings with other repository users who work with IntelliJ IDEA.
Associate different directories within the project with different Git repositories
- Open the project that you want to put under Git.
- From the main menu, choose VCS | Import into Version Control | Create Git Repository.
- In the dialog that opens, specify the directory where a new Git repository will be created.Git does not support external paths, so if you choose a directory that is outside your project root, make sure that the folder where the repository is going to be created also contains the project root.
- If you are creating multiple Git repositories inside the project structure, repeat the previous steps for each directory.
After you have initialized a Git repository for your project, you need to add project files to the repository.
Add files to the local repository
- In the Local Changes view, expand the Unversioned Files node. The position of the Local Changes view depends on which method you use to commit changes. If you are using the Commit dialog, uncommited changes are managed in the Local Changes tab of the Version Control tool tool window. Starting from IntelliJ IDEA version 2020.1, you can switch to a non-modal commit interface: in the Settings/Preferences dialog Ctrl+Alt+S go to Version Control | Commit and select the Use non-modal commit interface option (enabled by default for new installations). In this case, local changes and changelists are managed from the Commit tool window Alt+0.
- Select the files you want to add to Git or the entire changelist and press Ctrl+Alt+A or choose Add to VCS from the context menu.You can also add files to your local Git repository from the Project tool window: select the files you want to add, and press Ctrl+Alt+A or choose Git | Add from the context menu.
When Git integration is enabled in your project, IntelliJ IDEA suggests adding each newly created file under Git, even if it was added from outside IntelliJ IDEA. You can change this behavior in the Settings/Preferences dialog Ctrl+Alt+S under Version Control | Confirmation. If you want certain files to always remain unversioned, you can ignore them.
If you attempt to add a file that's on the .gitignore list, IntelliJ IDEA will suggest force adding it. Clicking Cancel in the confirmation dialog only cancels force adding ignored files - all other files will be added to the Git repository.
Exclude files from version control (ignore)
Sometimes you may need to leave certain files unversioned. These can be VCS administration files, artifacts of utilities, backup copies, and so on. You can ignore files through IntelliJ IDEA, and the IDE will not suggest adding them to Git and will highlight them as ignored.
You can only ignore unversioned files, that is files that you see in the Unversioned Files changelist. If a file is added to Git but not committed, you can right-click it in the Local Changes view and choose Rollback.
Git lets you list ignored file patterns in two kinds of configuration files:
- .git/info/exclude file.
Patterns listed in this file only apply to the local copy of the repository.This file is created automatically when you initialize or check out a Git repository. - One or more .gitignore files in the VCS root directory and its subdirectories.
These files are checked into the repository so that the ignore patterns in them are available to the entire team. Therefore, it is a most common place to store the ignored file patterns.If there is no .gitignore file in the VCS root directory, you can right-click anywhere in the Project window , choose New | File and type .gitignore in the New File dialog.To create a .gitignore file in Windows Explorer, create a file named .gitignore. and Windows will rename it automatically to .gitignore.
Add files to .gitignore or .git/info/exclude
- Decide what kind of Git configuration file you are going to use to ignore files. If in doubt, use .gitignore.
- Locate the unversioned file or folder you want to ignore in the Local Changes view or in Project tool window. File colors in these views help you identify the status of the file.
- Right click the selection and choose Git | Add to .gitignore or Git | Add to .git/info/exclude.
File colors in these views help you identify the status of the file.
If you need to exclude files by a certain pattern, or files of a certain type, you can edit the
.gitignore
or .git/info/exclude
file directly. See .gitignore patterns format If you want ignored files to be also displayed in the Local Changes view , click on the toolbar and select Show Ignored Files.
Check project status
IntelliJ IDEA allows you to check the status of your local working copy compared to the repository version of the project. It uses specific colors to let you see which files have been modified, which new files have been added to the VCS, and which files are not being tracked by Git.
Open the Local Changes view.
- The Default changelist shows all files that have been modified since you last synchronized with the remote repository (highlighted in blue), and all new files that have been added to the VCS but have not been committed yet (highlighted in green).
- The Unversioned Files changelist shows all files that have been added to your project, but that are not being tracked by Git.
For more info on changelists, see Group changes into different changelists.
Track changes to a file in the editor
You can also track changes to a file as you modify it in the editor. All changes are highlighted with change markers that appear in the gutter next to the modified lines, and show the type of changes introduced since you last synchronized with the repository. When you commit changes to the repository, change markers disappear.
The changes you introduce to the text are color-coded:
- line added.
- line changed.
You can customize the default colors for line statuses in the SettingsPreferences dialog Ctrl+Alt+S under Editor | Color Scheme | VCS.
When you delete a line, the following marker appears in the gutter: .
You can manage changes using a toolbar that appears when you hover the mouse cursor over a change marker and then click it. The toolbar is displayed together with a frame showing the previous contents of the modified line:
You can roll back changes by clicking and explore the differences between the current and the repository version of the current line by clicking .
Instead of reverting the whole file, you can copy any part of the contents of this popup and paste it into the editor.
Add a remote repository
To be able to collaborate on your Git project, you need to configure remote repositories that you fetch data from and push to when you need to share your work.
If you have cloned a remote Git repository, for example from GitHub, the remote is configured automatically and you do not have to specify it when you want to synchronize with it (in other words, when you perform a pull or a push operation). The default name Git gives to the remote you've cloned from is origin.
However, if you created a Git repository based on local sources, you need to add a remote repository for other contributors to be able to push their changes to it, and for you to be able to share the results of your work.
Define a remote
- Create an empty repository on any Git hosting, such as Bitbucket or GitHub.You can create a repository on GitHub without leaving IntelliJ IDEA: see Share a project on GitHub.
- Invoke the Push dialog when you are ready to push your commits by selecting VCS | Git | Push from the main menu, or press Ctrl+Shift+K.
- If you haven't added any remotes so far, the Define remote link will appear instead of a remote name. Click it to add a remote.
- In the dialog that opens, specify the remote name and the URL where it will be hosted, and click OK.
In some cases, you also need to add a second remote repository. This may be useful, for example, if you have cloned a repository that you do not have write access to, and you are going to push changes to your own fork of the original project. Another common scenario is that you have cloned your own repository that is somebody else's project fork, and you need to synchronize with the original project and fetch changes from it.
Add a second remote
- From the main menu, choose VCS | Git | Remotes. The Git Remotes dialog will open.
- Click the Add button on the toolbar or press Alt+Insert.
- In the dialog that opens, specify the remote name and URL and click OK.
To edit a remote (for example, to change the name of the original project that you have cloned), select it in the Git Remotes dialog and click the Edit button on the toolbar, or press Enter.
To remove a repository that is no longer valid, select it in the Git Remotes dialog and click the Remove button on the toolbar, or press Alt+Delete.
Git Download Mac Os
You can also edit a remote from the Push Dialog by clicking its name.
Learn more from this video:
Git Client For Mac
Last modified: 09 September 2020