banner



How To Use Git Commands In Windows

How to install and use Git on Windows

Updated: 06/thirty/2020 past Reckoner Hope

Git on Windows

Past default, Git is installed on Linux and macOS computers every bit a control line option. Withal, Microsoft Windows does not include a Git command. Below are the steps on how to install and use Git and GitHub on Microsoft Windows.

Installing Git on Windows

  1. Open the Git website.
  2. Click the Download link to download Git. The download should automatically offset.
  3. Once downloaded, commencement the installation from the browser or the download folder.
  4. In the Select Components window, leave all default options checked and bank check any other additional components you want installed.
  5. Next, in the Choosing the default editor, used by Git unless you're familiar with Vim we highly recommend using a text editor y'all're comfortable using. If Notepad++ is installed, we suggest using information technology as your editor. If Notepad++ is not installed, yous can cancel the install and install Notepad++ and then restart the GitHub install.
  6. Next, in the Adjusting your PATH environs, we recommend keeping the default Use Git from the command line and also from 3rd-party software equally shown beneath. This option allows you lot to utilise Git from either Git Bash or the Windows Control Prompt.

Git install adjust path

  1. Next, we recommend leaving the default selected as Utilize OpenSSH.
  2. Next, in Choosing HTTPS send backend, leave the default Utilise the OpenSSL library selected.
  3. In the Configuring the line ending conversions, select Checkout Windows-mode, commit Unix-mode line endings unless yous need other line endings for your work.
  4. In the Configuring the terminal emulator to use with Git Bash window, select Employ MinTTY (the default terminal of MSYS2).
  5. On the Configuring actress options window, leave the default options checked unless you need symbolic links.
  6. Click the Install button
  7. In one case completed, you can check the option to Launch Git Bash if you want to open a Bash command 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 control line and not use a GUI interface. You lot'll simply be using the control line to interface with Git to manage the files. Editing tin all the same exist washed through a text editor or IDE of your choice. If y'all're new to the control line, you can discover help with navigating the Windows control line and Linux (Fustigate) through the links below.

  • How to use the Windows command line (DOS).
  • Linux trounce tutorial.

Configuring and connecting to a remote repository

In our example, we're using GitHub as a storage for our remote repository. Beneath are the steps on how you lot tin connect to a GitHub repository. If you are new to GitHub, see: How to create a GitHub repository.

  1. From the command line, move to the directory you want to comprise your Git repository.
  • How to modify a directory or open up a folder.
  1. Type the following control to configure your Git username, where <your name> volition be your GitHub username.
git config --global user.name "<your name>"
  1. After entering the in a higher place command, you'll exist returned to the command prompt. Adjacent, enter your e-post address by typing the post-obit command, where <your email> is your e-mail address.
git config --global user.email "<your e-mail>"
  1. One time the to a higher place steps are completed, you'll be prepare to connect to a remote repository. To find the repository address, go to a repository on GitHub and click the Clone or download repository link to get the address. For example, nosotros've created a repository called "instance" at https://github.com/Computerhope/example.git address. Copy the address to your clipboard.
  2. Once copied go dorsum to the command line and blazon the following command, where <URL> is the address yous copied. To paste that address into the command line right-click in the control line window and click paste.
git clone <URL>
  1. One time the Git repository is created, you'll take a new directory in your current directory with the name of the Git repository.
  2. Once the Git remote repository is cloned to your local repository, a new folder in the current directory should announced with the name of the Git repository. For case, in our "example" Git nosotros would have a new directory called "example". Use the cd command to change into the new directory.
  3. One time in the new directory, blazon the following command to list the remote repositories.
git remote
  1. If successful, the output is "origin," which is a special name that refers to the remote repository.
  2. To encounter the aliases (URL or path), type the following command.
git remote -five

Running each of the above commands give y'all an output similar to what is shown in our example beneath.

Git listing remote repositories

Now that y'all've connected to a remote repository on GitHub yous're ready to start working on the files and pushing and pulling files every bit you update the files.

Working in your local repository and pushing files

After following the above steps and cloning a remote repository, you lot can work on the files equally you normally would. You 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

  1. Create a new file in the Git directory by typing the following command from either the Bash or Windows command line. The following control opens and creates a file called example.txt in Notepad. In Git Fustigate, yous could also apply the touch control to create a blank new file and then type "showtime <proper noun of file>" to open the file in your favorite text editor.
start notepad example.txt
  1. In the text editor, enter some text into the file and save and exit the file.
  2. Back at the command line blazon the following command to get the electric current status of your co-operative and untracked files.
git status
  1. Git displays a window similar to the instance shown below, showing that the file we created is new and untracked past Git.

Git status

  1. We'll at present want to add this file to Git to exist tracked by typing the following command. If your file is not named "example.txt," you'd desire to alter the text to the name of your file.
git add example.txt
  1. After entering the to a higher place control, the file is added as a new file also known every bit staging. Typing git status again shows you in green that the file is a new file that is ready to be committed.
  2. Adjacent, blazon the following command to commit the changes made in the local workspace to the local repository. In the example below, our notes "Kickoff example" should be notes that would make sense anybody working on your project.
git commit -1000 "First example"

Notation

You tin can also type git commit with no additional tags or options. However, when doing this it opens a vim similar editor that can be difficult for those not familiar with the vim to utilise. If yous type this control press "i" to enter insert fashion and blazon the notes for the commit on the first line, press Esc, and then type ":wq" to relieve, go out, and commit. Nosotros suggest using the above command because information technology'south easier for more than people to use.

  1. Finally, now that changes are moved from your workspace into your local repository it'due south ready to be pushed to the remote repository. Type the following control to button all changes to the remote repository.

Tip

If you desire to follow the progress, you can blazon git status once more to run into the electric current status. You can also type git log to see a log of changes.

git push

Note

Yous'll exist asked for your GitHub username and password if your estimator has not logged in to Git from the command line.

Once the file is pushed, information technology appears in your GitHub remote repository and is available to everyone else who're working with the same repository.

Modifying a file and pushing to remote repository

  1. Edit and modify one or more files in your Git.
  2. Type git condition to run across the condition of all the files not nevertheless committed from the workspace to the local repository.
  3. Type the following control to add all files. The unmarried period indicates that y'all want all files to be added to the local repository. Some people may likewise utilise git add -A to add all.

Tip

Yous can too apply wildcards instead of a period. For example, if you wanted to add all text files y'all could type *.txt instead of a single menstruation to only add text files.

git add .
  1. One time the files are added, type the following command to commit. Change the notes to use to your commit.
git commit -k "2nd update"
  1. Finally, blazon git push to push the commit to the remote repository.

Tip

If you're working with a lot of other people, nosotros'd recommend you pull (explained below) before committing. If your local repository is not the aforementioned equally the remote repository (excluding your new changes), the commit fails. For example, if someone has added new files to the remote repository while yous've been working and you try commit, it fails until you pull.

Pulling or fetching updates from the remote repository

If information technology's been awhile since yous've committed any 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 earlier committing, it verifies your local repository and the remote repository are the aforementioned 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 upward to you lot to manually set the files with the conflicts.

Tip

Use the git status command to see the status and merge disharmonize data.

Open up the file with the disharmonize to offset correcting the errors. In the example file beneath, we had a text file with one line of text and in the local repository nosotros added the text "update1" to the file. Even so, during the same fourth dimension, 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 electric current branch and everything after "=======" every bit the remote changes followed by ">>>>>>> < hash >" to marking the end.

Another file that is uploaded in-between pulls. <<<<<<< Head update1 ======= update2 >>>>>>> 62ee0eeba2e5b94d10574c1a6a68216e9b392e4c

To resolve this merge disharmonize, we would need to decide what text we wanted to proceed, update, or remove. In this example, we want to go on "update1" and "update2" in the social club they're listed and then we would only demand to remove the Git markings to brand the file resemble the post-obit example.

Another file that is uploaded in-between pulls. update1 update2

Annotation

If you're working with a big file, it'southward a expert idea to search the file for "Head" considering there may be more than one conflict.

Once the changes are made in the file, we could salve the file and so perform the post-obit git commands to update the fixes.

git add .
git commit -m "Fixed the merge conflict"
git push button origin principal

The example given in this merge conflict is a very bones example. When dealing with a file with more than a few lines of text or large sections of code, merge conflict tin get a lot more confusing. To make it easier to bargain with merge conflicts, y'all can use the command git mergetool to apply a merge tool, such every bit WinMerge or another popular merge tool.

Creating a Git co-operative

Creating a branch allows you lot to create a duplicate of the primary (trunk) and make several updates without affecting the main. For example, when developing a plan if a large set was need that could take weeks or months, a branch could exist created for that fix. Once you've fixed the bug, you could merge your branch back into the master.

To create a co-operative in your local repository, follow the steps below.

  1. In the Git master directory, type the following command, where "<New Branch>" is the proper noun of the new co-operative name. For example, we could call the co-operative "examplebranch".
git co-operative <New Branch>
  1. Next, type the following command to switch to the branch.
git checkout <Branch Name>
  1. After inbound the above command, the prompt (in Git Bash) changes from "master" to the branch name to indicate yous're working in a co-operative.
  2. From this indicate, you can keep to use Git and modify the files how y'all take in the past.
  3. To meet all available branches, you lot can use the git branch command. For example, typing git co-operative displays your local repository branches. Typing git branch -a displays all local and remote repositories.
  4. If you need to push the co-operative to the remote repository, you tin run the following command.
git push button --set-upstream origin <Co-operative Proper name>
  1. Finally, if you lot need to switch dorsum to the chief branch, you tin can type the post-obit command.
git checkout master

How to merge a branch dorsum into the master

After completing your piece of work, you'll want to merge information technology dorsum into the master or another branch by following the steps below.

  1. Move into the branch you desire to merge into. For example, if you wanted to merge back into the primary, blazon the following control.
git checkout principal
  1. Once in the principal, type the post-obit control to merge the branch.
git merge <Branch Proper noun>
  1. Once the merge is performed, add the files.
  2. Next, commit the changes.
  3. Once merged and committed, push the merge past typing the following control. If you lot get conflicts during the merge, run into our how to deal with merge conflicts section.
git button

How to delete a local and remote branch

If, afterward merging a branch you no longer want to keep the local or remote co-operative, you tin perform the following commands.

To delete the local branch, type the following command.

git branch -d <Branch Name>

To delete the remote co-operative, type the post-obit command.

git button origin --delete <Branch Proper name>

Source: https://www.computerhope.com/issues/ch001927.htm

Posted by: clementwrapprand.blogspot.com

0 Response to "How To Use Git Commands In Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel