Git for Windows

Table of Content


Install Git for Windows on Windows 10 Pro and manage version control with Git Bash. It is assumed that the compilation and execution will be done on Ubuntu 18.04 LTS on WSL on Windows 10 Pro. Therefore, the linefeed code should always be in Linux format. This linefeed code stuff is a trap for beginners, so be careful.
Download Git for Windows from here and start installation by double-clicking. Basically, the default is OK, but in the question about line endings appearing nearly at the end (Configuring line ending conversions), click the third option below. This allows you to work while always maintaining the Linux linefeed code.

Checkout as-is, commit as-is

Git for Windows can be updated in Git Bash as follows. If a new version is available, you will be asked like Download and install Git for Windows 2.27.0 [N/y]?; type y. The download will start and will be installed automatically.

$ git update-git-for-windows

Display file names in Japanese

Follow the steps below to prevent garbled Japanese file names when using ls. If there are no files having Japanese characters, skip the following.

Open the registry editor with regedit and change the value of FaceName in Git Bash of Console of HKEY_CURRENT_USER to "*MS Gothic".
In the home directory of Git Bash (usually /c/Users/your_name/), Create .bashrc containing the following and restart Git Bash.

$ alias ls='ls --show-control-chars'

Initial setting

When you use Git Bash for the first time, do the following only once. The first is the setting of the editor, which is optional, but if you set a familiar one, it will be easier to enter a comment when committing.

git config --global core.editor "'/C/Program Files/Hidemaru/Hidemaru.exe' //fu8"
git config --global "Jun Sasaki"
git config --global ""
git config --global core.quotepath false

Git clone from remote repository

In an appropriate directory, copy the address of Clone with SSH in a remote repository and execute as follows.

$ git clone

project directory will be created under the current directory and copied into it.

Create a new local repository

To create a repository for the first time in a local repository instead of cloning it from a remote repository, after moving to the directory where you want to manage version control, execute the following:

$ git init

.git directory (hidden directory) is created; configuration files and repository data are stored.

Register files in local repository

Register the files you want to manage in various ways.

Register all files with extension of F, including those in sub directories

$ git add *.F

File of makefile in subdirectory BIO_source is indexed

$ git add BIO_source/makefile

Index all files, including those in subdirectories

$ git add -A

Remove file from version control (file itself remains)

$ git rm --cached test.F

Check the status of index registration

$ git status

Add -s option for shortened display

$ git status -s

Commit to local repository

An editor will open, so enter a comment.

$ git commit


It is a method of canceling the commit or returning the repository to the specified previous commit due to missing file registration.

Restore the last commit
If you just want to cancel the commit and continue working, do the following.

$ git reset --soft HEAD^

--soft can be omitted. If you switch --soft to --hard, the index working tree will also revert to the previous commit. That is, the work just before the present commit will be lost; the state immediately after the previous commit will be restored.

Check history of past commits
Check the commit status with git reflog.

$ git reflog

Return to a specified commit status
Use git reflog to figure out the commit number such as HEAD@{2} of the commit you want to restore; do the following. If you specify --hard, the index working tree will be completely restored to the state at the previous commit.

$ git reset --hard HEAD@{2}

Display repository file list

git ls-files

Index and commit all changes to files under version control

There is no new addition or deletion of files, only changes of files are targeted.

$ git add -u
$ git commit

Next is the same as above.

$ git commit -a

Reflect to remote repository (push)

The contents such as changes in the local repository are reflected in the remote repository.

$ git push

Display change history

$ git log

Tag with ### v1.0

$ git tag v1.0

List tags

$ git tag

Remove v1.0 tag

$ git tag -d v1.0

Check out tag v1.0
If option -f is added, it will be forcibly switched even during work.

$ git checkout [-f] v1.0

Branch operations

Create a new devel branch
Create and switch it to the current branch.

$ git checkout -b devel

List branches
Add -a to display including remote repositories. The current branch will be marked with *.

$ git branch [-a]

Switch to existing devel branch

$ git checkout devel

Switch to master branch

$ git checkout master

Display branch information
Append -a to display all pieces of branch information.

$ git show-branch [-a]

Remove branch devel

$ git branch -d devel

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.