Set up a Git repository | PhpStorm (2024)

When you clone an existing Git repository, or put an existing project under Git version control, PhpStorm automatically detects if Git is installed on your computer. If the IDE can't locate a Git executable, it suggests downloading it.

PhpStorm 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, PhpStorm searches for Git in WSL and uses it from there. Also, PhpStorm automatically switches to Git from WSL for projects that are opened when you use the \\wsl$ path.

If you need to manually configure PhpStorm to use Git from WSL, go to the Version Control | Git page of the IDE settings Ctrl+Alt+S, click the Browse icon in the Path to Git executable field and select Git from WSL via the \wsl$ path, for example, \\wsl$\debian\usr\bin\git.

Check out a project from a remote host (clone)

PhpStorm allows you to check out (in Git terms clone) an existing repository and create a new project based on the data you've downloaded.

  1. From the main menu, select Git | Clone, or, if no project is currently opened, click Get from VCS on the Welcome screen.

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

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

Put an existing project under Git version control

You can create a local Git repository based on the existing project sources.

Associate the entire project with a single Git repository

  1. Open the project that you want to put under Git.

  2. Press Alt+` to open the VCS Operations Popup and select Enable Version Control Integration.

    Alternatively, from the main menu, select VCS | Enable Version Control Integration.

  3. Choose Git as the version control system and click OK.

  4. After VCS integration is enabled, PhpStorm 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 PhpStorm.

    Set up a Git repository | PhpStorm (1)

Associate different directories within the project with different Git repositories

  1. Open the project that you want to put under Git.

  2. From the main menu, choose VCS | Create Git Repository.

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

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

  1. In the Commit tool window Alt+0, expand the Unversioned Files node.

  2. 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, PhpStorm suggests adding each newly created file under Git, even if it was added from outside PhpStorm. You can change this behavior in the Version Control | Confirmation page of the IDE settings Ctrl+Alt+S. If you want certain files to always remain unversioned, you can ignore them.

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 PhpStorm, 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.

Add files to .gitignore or .git/info/exclude

  1. Decide what kind of Git configuration file you are going to use to ignore files. If in doubt, use .gitignore.

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

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

Check project status

PhpStorm 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 Changes 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:

  • Set up a Git repository | PhpStorm (2) line added.

  • Set up a Git repository | PhpStorm (3) line changed.

  • Set up a Git repository | PhpStorm (4) line deleted.

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:

Set up a Git repository | PhpStorm (5)

You can roll back changes by clicking Set up a Git repository | PhpStorm (6) and explore the differences between the current and the repository version of the current line by clicking Set up a Git repository | PhpStorm (7).

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

If you created a Git repository based on local sources, you need to add a remote repository to be able to collaborate on your Git project, as well as to eliminate the risks of storing all of your codebase locally. You push changes to a remote repository when you need to share your work and pull data from it to integrate changes made by other contributors into your local repository version.

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 sync with it. The default name Git gives to the remote you've cloned from is origin.

For information on how to share project settings for different project formats, see Share project settings through VCS.

Define a remote

  1. Create an empty repository on any Git hosting, such as Bitbucket or GitHub. You can create a repository on GitHub without leaving PhpStorm: see Share a project on GitHub.

  2. Invoke the Push dialog when you are ready to push your commits by selecting Git | Push from the main menu, or press Ctrl+Shift+K.

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

  4. In the dialog that opens, specify the remote name and the URL where it will be hosted, and click OK.

Add a second remote

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.

  1. From the main menu, choose Git | Manage Remotes. The Git Remotes dialog will open.

  2. Click the Add Set up a Git repository | PhpStorm (8) button on the toolbar or press Alt+Insert.

  3. 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), right-click the remote branch in the Branches pane of the Git Log tool window, and select Edit Remote from the context menu.

    You can also edit a remote from the Push Dialog by clicking its name.

  • To remove a repository that is no longer valid, right-click it in the Branches pane of the Git Log tool window, and select Remove Remote from the context menu.

Learn more from this video:

Last modified: 14 September 2022

Git Sync with a remote Git repository (fetch, pull, update)

Set up a Git repository | PhpStorm (2024)

FAQs

How to setup a Git repository? ›

  1. In the upper-right corner of any page, use the drop-down menu, and select New repository.
  2. Type a short, memorable name for your repository. ...
  3. Optionally, add a description of your repository. ...
  4. Choose a repository visibility. ...
  5. Select Initialize this repository with a README.
  6. Click Create repository.

How do I create a Git repository for beginners? ›

An Intro to Git and GitHub for Beginners (Tutorial)
  1. Step 0: Install git and create a GitHub account. ...
  2. Step 1: Create a local git repository. ...
  3. Step 2: Add a new file to the repo. ...
  4. Step 3: Add a file to the staging environment. ...
  5. Step 4: Create a commit. ...
  6. Step 5: Create a new branch. ...
  7. Step 6: Create a new repository on GitHub.

How do I make a good repository on GitHub? ›

  1. Add Description (with Emojis & Link) This is the lowest hanging fruit in creating an impressive GitHub repository. ...
  2. Add Tags. Adding tags is the next and most crucial step in this article. ...
  3. Add License. ...
  4. Add Readme. ...
  5. Use Descriptive Commit Messages. ...
  6. BONUS: Use Multiple Languages.
May 7, 2022

What is the command to initialize a repository group answer choices? ›

The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository.

How do I setup a Git repository in Windows 10? ›

You run these one-time setup activities to start contributing:
  1. Determine the appropriate repository.
  2. Fork the repository to your GitHub account.
  3. Choose a local folder for the cloned files.
  4. Clone the repository to your local machine.
  5. Configure the upstream remote value.
Oct 11, 2022

What is git setup? ›

The git config command is a convenience function that is used to set Git configuration values on a global or local project level. These configuration levels correspond to . gitconfig text files. Executing git config will modify a configuration text file.

How to set a remote repository git? ›

Adding a remote repository

To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. The git remote add command takes two arguments: A remote name, for example, origin.

Should beginners use GitHub? ›

Whether you are working on personal projects alone or are part of a team working on huge enterprise software, GitHub is a useful tool. If you're alone, you can use it to store your code and show off what you've done to others.

What is difference between GitHub and Git? ›

GitHub, meanwhile, serves as a host for Git repository teams to store their code in a centralized location. While Git is a tool that's used to manage multiple versions of source code edits that are then transferred to files in a Git repository, GitHub serves as a location for uploading copies of a Git repository.

Do professionals use GitHub? ›

Yes, Github is a technical skill that you can put on your resume. It is used by numerous companies who want to hire professionals with working knowledge of Github. It is used by companies to make software development easier and faster by monitoring code changes made by team members.

What does a good GitHub page look like? ›

Generally speaking, one's GitHub profile is considered good if it: Has decent amount of projects for others to see. Has frequent and good number of commits(little green squares) on the timeline of the profile. Preferably more than 1000.

How do you plan to use GitHub best answer? ›

  1. Create an account on GitHub. Follow the steps and create a repository using GitHub UI. ...
  2. Now try to do this from command line. Follow all the steps, read on the web and avoid using GitHub UI. ...
  3. Push your hello world programs to GitHub. ...
  4. Search projects on GitHub based on your favorite programming language, or o.

How do I initialize a Git repository from the command line? ›

Start a new git repository
  1. Create a directory to contain the project.
  2. Go into the new directory.
  3. Type git init .
  4. Write some code.
  5. Type git add to add the files (see the typical use page).
  6. Type git commit .

What is Git repository command? ›

A Git repository tracks and saves the history of all changes made to the files in a Git project. It saves this data in a directory called . git , also known as the repository folder. Git uses a version control system to track all changes made to the project and save them in the repository.

What are the basic git commands? ›

Git commands
  • git add. Moves changes from the working directory to the staging area. ...
  • git branch. This command is your general-purpose branch administration tool. ...
  • git checkout. ...
  • git clean. ...
  • git clone. ...
  • git commit. ...
  • git commit --amend. ...
  • git config.

How do I host a git repository in Windows? ›

4.1. Hosting your own Git server
  1. First make sure you have installed the SSH tooling. ...
  2. If you have not yet installed Git on your server, you need to do this too. ...
  3. Create a new user and set a password for the Git system. ...
  4. Now log in with your Git user and create a bare repository. ...
  5. Now you can push to the remote repository.

How do I add a git repository to my computer? ›

To clone your Github repo on Windows.
  1. Open Git Bash. If Git is not already installed, it is super simple. ...
  2. Go to the current directory where you want the cloned directory to be added. ...
  3. Go to the page of the repository that you want to clone.
  4. Click on “Clone or download” and copy the URL.

How do I create a GitHub repository in Windows? ›

Adding a repository from your local computer to GitHub Desktop
  1. In the File menu, click Add Local Repository.
  2. Click Choose... and, using the Finder window, navigate to the local repository you want to add.
  3. Click Add Repository.

How do I clone a Git repository to my local machine? ›

Cloning a repository syncs it to your local machine.
...
If you don't have SourceTree, download the application first.
  1. From the repository, select the Clone button.
  2. In the Clone this repository dialog, select the Clone in Sourcetree button.
  3. If necessary, update the Destination Path or Bookmark Name. ...
  4. Select the Clone button.

What is the difference between Git and GitHub? ›

While Git is a tool that's used to manage multiple versions of source code edits that are then transferred to files in a Git repository, GitHub serves as a location for uploading copies of a Git repository. In a sense, then, there's no comparison when it comes to Git vs. GitHub as far as their function.

How do you install a repository? ›

How to Install Git and Clone a Repository
  1. Open Google and search for git on windows.
  2. Find a version that is compatible with your operating system. ...
  3. Click on the link. ...
  4. After this, go to the folder with the downloaded file and run it.
  5. Choose the installation path and continue.

How do I clone a local Git repository? ›

To Git clone a repository navigate to your preferred repository hosting service like GitHub, select the repository you want to clone, copy the repository URL via HTTPS or SSH, type git clone in the command line, paste the URL, and hit enter .

How do I clone git for the first time? ›

Type git clone , and then paste the URL you copied earlier. Press Enter to create your local clone.
...
Cloning a repository
  1. On GitHub.com, navigate to the main page of the repository.
  2. Above the list of files, click Code.
  3. Copy the URL for the repository. ...
  4. Open Terminal .

How do you clone a repo and make it your own? ›

Cloning a repository
  1. In the File menu, click Clone Repository.
  2. Click the tab that corresponds to the location of the repository you want to clone. ...
  3. Choose the repository you want to clone from the list.
  4. Click Choose... and navigate to a local path where you want to clone the repository.
  5. Click Clone.

How to pull code from git? ›

Now go back to the original folder and follow the instructions:
  1. First, run git status. Git will tell you the repository is clean, nothing to worry about.
  2. Then run git fetch.
  3. Next, run git status again. Git will say your branch is one commit behind.
  4. Finally, run git pull to update your local branch.
Jul 9, 2021

Why is it called Git? ›

The name "git" was given by Linus Torvalds when he wrote the very first version. He described the tool as "the stupid content tracker" and the name as (depending on your mood): - random three-letter combination that is pronounceable, and not actually used by any common UNIX command.

Can I use Git without GitHub? ›

You can use Git without ever using an online host like Github; you would still get the benefits of saved backups and a log of your changes. However, using Github (or the others) allows you store this on a server so that you can access anywhere or share.

Top Articles
Latest Posts
Article information

Author: Carmelo Roob

Last Updated:

Views: 6239

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Carmelo Roob

Birthday: 1995-01-09

Address: Apt. 915 481 Sipes Cliff, New Gonzalobury, CO 80176

Phone: +6773780339780

Job: Sales Executive

Hobby: Gaming, Jogging, Rugby, Video gaming, Handball, Ice skating, Web surfing

Introduction: My name is Carmelo Roob, I am a modern, handsome, delightful, comfortable, attractive, vast, good person who loves writing and wants to share my knowledge and understanding with you.