How To Run Git In Windows
How to install and use Git on Windows
Updated: 06/xxx/2020 by Computer Hope
Past default, Git is installed on Linux and macOS computers as a command line option. All the same, Microsoft Windows does non include a Git control. Below are the steps on how to install and utilize Git and GitHub on Microsoft Windows.
Installing Git on Windows
- Open the Git website.
- Click the Download link to download Git. The download should automatically start.
- Once downloaded, start the installation from the browser or the download folder.
- In the Select Components window, leave all default options checked and check any other boosted components you want installed.
- Next, in the Choosing the default editor, used by Git unless you're familiar with Vim nosotros highly recommend using a text editor you lot're comfortable using. If Notepad++ is installed, nosotros suggest using it as your editor. If Notepad++ is not installed, y'all tin can cancel the install and install Notepad++ and so restart the GitHub install.
- Next, in the Adjusting your PATH environment, nosotros recommend keeping the default Utilise Git from the command line and as well from third-party software every bit shown below. This selection allows you to use Git from either Git Bash or the Windows Command Prompt.
- Next, we recommend leaving the default selected as Use OpenSSH.
- Next, in Choosing HTTPS ship backend, go out the default Use the OpenSSL library selected.
- In the Configuring the line ending conversions, select Checkout Windows-mode, commit Unix-mode line endings unless you demand other line endings for your work.
- In the Configuring the last emulator to use with Git Bash window, select Use MinTTY (the default terminal of MSYS2).
- On the Configuring extra options window, leave the default options checked unless you need symbolic links.
- Click the Install push
- In one case completed, you tin can check the option to Launch Git Bash if you want to open a Fustigate control line or, if you selected the Windows command line, run Git from the Windows command line.
Tip
We highly recommend you use Git from the command line and not employ a GUI interface. You'll just exist using the command line to interface with Git to manage the files. Editing tin can still be done through a text editor or IDE of your choice. If y'all're new to the command line, you can observe help with navigating the Windows command line and Linux (Bash) through the links below.
- How to employ the Windows control line (DOS).
- Linux shell tutorial.
Configuring and connecting to a remote repository
In our example, we're using GitHub every bit a storage for our remote repository. Below are the steps on how you can connect to a GitHub repository. If you are new to GitHub, encounter: How to create a GitHub repository.
- From the control line, motility to the directory you want to contain your Git repository.
- Type the following command to configure your Git username, where <your name> will be your GitHub username.
git config --global user.name "<your name>"
- After entering the higher up command, yous'll be returned to the control prompt. Next, enter your e-mail service address by typing the following control, where <your e-mail> is your e-mail address.
git config --global user.email "<your e-mail>"
- Once the to a higher place steps are completed, y'all'll be ready to connect to a remote repository. To discover the repository address, go to a repository on GitHub and click the Clone or download repository link to go the address. For example, we've created a repository called "instance" at https://github.com/Computerhope/example.git address. Copy the address to your clipboard.
- Once copied get back to the command line and type the following control, where <URL> is the address you copied. To paste that address into the command line correct-click in the command line window and click paste.
git clone <URL>
- Once the Git repository is created, you'll have a new directory in your current directory with the name of the Git repository.
- In one case the Git remote repository is cloned to your local repository, a new folder in the current directory should appear with the proper noun of the Git repository. For example, in our "example" Git we would have a new directory chosen "example". Apply the cd control to modify into the new directory.
- One time in the new directory, type the following control to list the remote repositories.
git remote
- If successful, the output is "origin," which is a special name that refers to the remote repository.
- To run into the aliases (URL or path), blazon the post-obit command.
git remote -v
Running each of the in a higher place commands give you an output similar to what is shown in our example below.
Now that you've connected to a remote repository on GitHub you're ready to get-go working on the files and pushing and pulling files as you lot update the files.
Working in your local repository and pushing files
Subsequently post-obit the to a higher place steps and cloning a remote repository, you tin can work on the files as you ordinarily would. Yous tin can create new files or edit existing files from the command line or your favorite text editor. Below, are the steps of creating a new file, pushing that file, editing an existing file, and pushing the update.
Creating a new file and pushing to remote repository
- Create a new file in the Git directory by typing the following command from either the Bash or Windows command line. The post-obit control opens and creates a file called instance.txt in Notepad. In Git Bash, you could also use the affect command to create a blank new file and and so type "start <name of file>" to open the file in your favorite text editor.
start notepad case.txt
- In the text editor, enter some text into the file and save and exit the file.
- Back at the command line type the following command to get the electric current status of your branch and untracked files.
git status
- Git displays a window similar to the case shown below, showing that the file we created is new and untracked by Git.
- We'll now desire to add together this file to Git to be tracked past typing the post-obit command. If your file is non named "instance.txt," you'd want to change the text to the name of your file.
git add example.txt
- After inbound the higher up command, the file is added equally a new file likewise known as staging. Typing git status again shows you in green that the file is a new file that is ready to be committed.
- Next, type the following control to commit the changes made in the local workspace to the local repository. In the example below, our notes "Showtime instance" should be notes that would make sense everyone working on your project.
git commit -m "Commencement instance"
Note
You can also type git commit with no additional tags or options. Still, when doing this it opens a vim like editor that tin be difficult for those not familiar with the vim to employ. If you type this command press "i" to enter insert mode and type the notes for the commit on the starting time line, press Esc, and then type ":wq" to save, exit, and commit. We propose using the above command because it's easier for more people to utilise.
- Finally, now that changes are moved from your workspace into your local repository it'southward ready to be pushed to the remote repository. Type the post-obit command to button all changes to the remote repository.
Tip
If you want to follow the progress, you can type git status again to run into the current status. Yous can also type git log to see a log of changes.
git push
Note
You'll be asked for your GitHub username and password if your computer has not logged in to Git from the command line.
Once the file is pushed, it appears in your GitHub remote repository and is bachelor to everyone else who're working with the same repository.
Modifying a file and pushing to remote repository
- Edit and change one or more than files in your Git.
- Type git status to see the status of all the files not nonetheless committed from the workspace to the local repository.
- Blazon the following command to add all files. The single menstruum indicates that you want all files to be added to the local repository. Some people may also use git add -A to add all.
Tip
You tin can also utilise wildcards instead of a menses. For case, if you wanted to add all text files you could blazon *.txt instead of a single flow to only add text files.
git add together .
- Once the files are added, blazon the following control to commit. Change the notes to utilize to your commit.
git commit -thou "Second update"
- Finally, blazon git button to push the commit to the remote repository.
Tip
If you lot're working with a lot of other people, we'd recommend you pull (explained below) before committing. If your local repository is not the same every bit the remote repository (excluding your new changes), the commit fails. For example, if someone has added new files to the remote repository while you've been working and yous endeavour commit, it fails until you pull.
Pulling or fetching updates from the remote repository
If information technology'south been awhile since you've committed any piece of work, perform the git pull command to get the latest updates from the remote repository and merge them into your local repository. By pulling updates from a repository before committing, information technology verifies your local repository and the remote repository are the same and prevents merge conflicts.
To get all changes without merging, run the git fetch command to grab all of the latest updates from the remote repository without merging changes.
How to deal with a Git merge conflict
When multiple people are working with the aforementioned files, you're going to encounter merge conflicts. When a conflict occurs, Git modifies your local files and it is upwardly to you to manually set up the files with the conflicts.
Tip
Use the git status command to run across the status and merge conflict information.
Open the file with the conflict to start correcting the errors. In the instance file below, nosotros had a text file with one line of text and in the local repository we added the text "update1" to the file. However, during the same time, the remote repository file was modified and added "update2" to the file on the same line. Git marks conflicts with "<<<<<<< HEAD" for lines in the current branch and everything subsequently "=======" as the remote changes followed past ">>>>>>> < hash >" to mark the finish.
Another file that is uploaded in-between pulls. <<<<<<< Head update1 ======= update2 >>>>>>> 62ee0eeba2e5b94d10574c1a6a68216e9b392e4c
To resolve this merge conflict, we would need to decide what text we wanted to keep, update, or remove. In this example, we want to keep "update1" and "update2" in the order they're listed and then we would merely need to remove the Git markings to make the file resemble the following example.
Another file that is uploaded in-betwixt pulls. update1 update2
Note
If you lot're working with a big file, it's a practiced idea to search the file for "Caput" because at that place may be more one conflict.
Once the changes are fabricated in the file, we could relieve the file and then perform the following git commands to update the fixes.
git add .
git commit -one thousand "Stock-still the merge conflict"
git push origin principal
The instance given in this merge conflict is a very basic instance. When dealing with a file with more than a few lines of text or big sections of code, merge conflict tin get a lot more disruptive. To arrive easier to deal with merge conflicts, you tin use the command git mergetool to use a merge tool, such as WinMerge or another popular merge tool.
Creating a Git branch
Creating a branch allows you to create a duplicate of the primary (trunk) and make several updates without affecting the main. For example, when developing a plan if a big ready was need that could take weeks or months, a branch could be created for that fix. Once you've stock-still the bug, you could merge your branch back into the chief.
To create a co-operative in your local repository, follow the steps below.
- In the Git master directory, blazon the following command, where "<New Branch>" is the proper noun of the new co-operative name. For instance, we could call the branch "examplebranch".
git branch <New Co-operative>
- Next, blazon the following command to switch to the branch.
git checkout <Co-operative Name>
- Later on inbound the in a higher place command, the prompt (in Git Bash) changes from "primary" to the branch name to indicate you're working in a branch.
- From this point, y'all can continue to use Git and modify the files how you have in the past.
- To run into all available branches, you can apply the git branch command. For example, typing git branch displays your local repository branches. Typing git branch -a displays all local and remote repositories.
- If you need to push the branch to the remote repository, you lot tin run the following command.
git push --set-upstream origin <Branch Name>
- Finally, if you need to switch back to the master branch, you can type the post-obit command.
git checkout master
How to merge a co-operative back into the chief
After completing your work, you'll want to merge it dorsum into the principal or some other branch by following the steps below.
- Move into the branch you desire to merge into. For example, if you wanted to merge back into the primary, blazon the following command.
git checkout principal
- In one case in the master, blazon the following command to merge the branch.
git merge <Branch Name>
- In one case the merge is performed, add the files.
- Next, commit the changes.
- One time merged and committed, push the merge past typing the following command. If yous get conflicts during the merge, meet our how to deal with merge conflicts department.
git button
How to delete a local and remote branch
If, after merging a branch you no longer want to keep the local or remote branch, you lot can perform the following commands.
To delete the local co-operative, type the post-obit command.
git branch -d <Co-operative Proper noun>
To delete the remote branch, type the following command.
git button origin --delete <Branch Name>
Source: https://www.computerhope.com/issues/ch001927.htm
Posted by: partridgevered1971.blogspot.com
0 Response to "How To Run Git In Windows"
Post a Comment