1. Information
1.1. General
1.2. Line Endings
About: core.autocrlf
If you’re programming on Windows and working with people who are not (or vice-versa), you’ll probably run into line-ending issues at some point. This is because Windows uses both a carriage-return character and a linefeed character for newlines in its files, whereas macOS and Linux systems use only the linefeed character. This is a subtle but incredibly annoying fact of cross-platform work. Many editors on Windows silently replace existing LF-style line endings with CRLF, or insert both line-ending characters when the user hits the enter key.
Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index, and vice versa when it checks out code onto your filesystem. You can turn on this functionality with the core.autocrlf setting. If you’re on a Windows machine, set it to true. This converts LF endings into CRLF when you check out code.
git config --global core.autocrlf true
If you’re on a Linux or macOS system that uses LF line endings, then you don’t want Git to automatically convert them when you check out files. However, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input. This setup should leave you with CRLF endings in Windows checkouts, but LF endings on macOS and Linux systems and in the repository.
git config --global core.autocrlf input
If you’re a Windows programmer doing a Windows-only project, then you can turn off this functionality, recording the carriage returns in the repository by setting the config value to false.
git config --global core.autocrlf false
2. Linux
2.1. Installation
sudo apt-get install git
2.2. Configuration
-
See https://stackoverflow.com/questions/16562121/git-diff-head-vs-staged/16562782.
-
git diffShow differences between Staged and Working Area. -
git diff --cachedShow differences between HEAD and Staged. -
git diff --stagedShow differences between HEAD and Staged. -
git diff HEADShow differences between HEAD and Working Area.
git config --global color.color always
git config --global core.autocrlf false
git config --global push.default simple
git config --global user.name 'Delta Software Labs'
git config --global user.email delta@deltasoftware.frl
git config --global user.name 'Douwe Kiestra'
git config --global user.email douwe@deltasoftware.frl
git config --global user.email douwe@grendelgames.com
git config --list # .git/config
git config --global --list # /home/<user>/.gitconfig
git config --system --list # /etc/gitconfig
git config --list --show-origin
# List all aliases.
git config --get-regexp ^alias
-
Contents of the ~delta/.gitconfig file.
[color] color = always [core] autocrlf = false [push] default = simple [user] name = Douwe Kiestra email = douwe@deltasoftware.frl
-
Contents of the ~douwe/.gitconfig file.
[color] color = always [core] autocrlf = false [push] default = simple [user] name = Douwe Kiestra email = douwe@grendelgames.com
2.3. Create New Repository
-
Sign in as delta-software-labs on https://github.com/login.
-
Click New.
-
Type Repository name |
<repo>. -
Type Description |
<description>. -
Select Choose visibility | Private.
-
Select Choose visibility | Public.
-
Enable Add README.
-
Select Add .gitignore | No .gitignore.
-
Select Add license | GNU General Public License v3.0.
-
Click Create repository.
-
Click the <> Code button and copy the HTTPS URL.
git clone https://github.com/delta-software-labs/<repo>.git cd <repo> touch <file> git add <file> git commit -m "<description>" git push
2.4. Usage
cd ~delta/github/git/delta-software-labs
git clone https://dhkiestra@github.com/dhkiestra/Documentation.git
git clone https://delta-software-labs@github.com/delta-software-labs/Documentation.git
git clone https://delta-software-labs@github.com/delta-software-labs/Test.git
cd Documentation
git status -s
vi <file>
git-diff-w <file>
git-diff-w <commit> <file>
git status -s
# Add unstaged changes in working directory.
git add <file>
# Discard unstaged changes in working directory.
git checkout -- <file>
# Unstage a file.
git restore --staged <file>
git status -s
git commit
git commit -m "<message>"
git status -s
git log --pretty=oneline
git log --pretty=format:"Commit %h%nAuthor: %an <%ae>%nDate: %ai%nMessage: %s%n"
git log --pretty=format:"%C(yellow)Commit %h%Creset%nAuthor: %an <%ae>%nDate: %ai%nMessage: %s%n"
??? # hg clone -r 264 http://smru-it@bitbucket.org/smru/windows windows.r264
git fetch && git log ..origin # hg incoming
git fetch && git log origin.. # hg outgoing
git pull
git push
git push --tags
git clone -b development https://smru-it@bitbucket.org/madhums/NeoCom-Mobile.git git clone https://smru-it@bitbucket.org/madhums/NeoCom.git git clone https://smru_ro@bitbucket.org/smru/NeoCom-Config.git cd NeoCom git log | more git branch git branch -r git branch -a git tag -l git remote -v update git status git pull git diff
2.5. Branches
# Create new 'test' branch. git branch test # Switch to 'test' branch. git checkout test # List branches. git branch # Delete branch 'test'. git branch -d test # List both remote-tracking branches and local branches. git branch --all git status git commit --message="" git status git checkout master git status git-incoming git-outgoing git pull git status git merge test
2.6. Initialization of new Bitbucket repository
-
Create a new git repository at bitbucket.org.
mkdir -p ~/bitbucket/git/smru cd ~/bitbucket/git/smru git clone https://smru-it@bitbucket.org/smru/NeoCom-Config.git git clone https://smru-it@bitbucket.org/smru/NeoCom-Device.git cd ~/bitbucket/git/smru/NeoCom-Config cp -a ../../madhums/NeoCom/* . cp -a ../../madhums/NeoCom/.gitignore . git status git add . git status git commit -m "first commit" git push -u origin master cd ~/bitbucket/git/smru/NeoCom-Device cp -a ../../madhums/NeoCom-Mobile/* . cp -a ../../madhums/NeoCom-Mobile/.gitignore . git status git add . git status git commit -m "first commit" git push -u origin master
2.7. Previous versions
# Find any commit that added or removed the pattern. git log -i -G <pattern> git log -i -S <pattern> git-log git checkout <commit> git checkout master
2.8. Search all committed files
git grep "<pattern>" $(git rev-list --all)
2.9. Undo commit
git reset HEAD~
# Undo last local commit (keep changes).
git reset --soft HEAD~1 # This removes the commit but keeps the files in your staging area,
# allowing you to amend the commit or make changes.
# Undo last local commit (discard changes).
git reset --hard HEAD~1 # This permanently removes the commit and all changes made in that commit.
# Undo multiple local commits (replace N with the number of commits).
git reset --hard HEAD~N
# Undo a pushed commit (safe).
git revert <commit-hash> # Creates a new commit that reverses the changes,
# which is safer for shared branches.
2.10. Version numbering
cd ~/github/git/delta-software-labs/Linux-Tools git describe --always --dirty --long --tags git tag -l git-log git commit git describe --always --dirty --long --tags git tag v4.6 git tag -l git describe --always --dirty --long --tags git push --tags git push
# Delete local tag. git tag --delete v1.4.4 git tag -l # Delete remote tag. git push --delete https://gitlab.com/dhkiestra/gitlabexercise.git v1.4.4
-
Update the version number in the package.json file.
3. macOS
3.1. Installation
-
Log in as smru.
-
Download the latest stable release from http://git-scm.com/downloads.
-
Start Finder.
-
Run the git-1.7.12.1-intel-universal-snow-leopard.dmg file.
-
Run the git-1.7.12.1-intel-universal-snow-leopard.pkg file.
-
Click Continue.
-
Click Install.
-
Click Close.
-
Close the Git 1.7.12.1 Snow Leopard Intel Universal window.
-
Close Finder.
3.2. Configuration
-
Contents of the ~/.gitconfig file.
[push]
default = simple
[user]
name = Douwe Kiestra
email = douwe@deltasoftware.frl email = dhkiestra@protonmail.com
username = delta
[alias] ; cdiff = diff --color-words
3.3. Usage
git clone -b development https://smru-it@bitbucket.org/madhums/NeoCom-Mobile.git git clone https://smru-it@bitbucket.org/madhums/NeoCom.git cd NeoCom git log | more git branch git branch -r git branch -a git tag -l git remote -v update git status git pull git diff
3.4. Usage of branches with Git
git branch test git checkout test git branch -a git status git commit -a git checkout master git status
3.5. Initialization of new Bitbucket repository
-
Create a new git repository at bitbucket.org.
mkdir -p ~/bitbucket/git/smru cd ~/bitbucket/git/smru git clone https://smru-it@bitbucket.org/smru/NeoCom-Config.git git clone https://smru-it@bitbucket.org/smru/NeoCom-Device.git cd ~/bitbucket/git/smru/NeoCom-Config cp -a ../../madhums/NeoCom/* . cp -a ../../madhums/NeoCom/.gitignore . git status git add . git status git commit -m "first commit" git push -u origin master cd ~/bitbucket/git/smru/NeoCom-Device cp -a ../../madhums/NeoCom-Mobile/* . cp -a ../../madhums/NeoCom-Mobile/.gitignore . git status git add . git status git commit -m "first commit" git push -u origin master
3.6. Version numbering
cd ~/bitbucket/git/smru/NeoCom-Config git tag -l git tag -a 0.2.0 -m '1st prototype version' git tag -a v1.0 -m "" <commit> git push --tags git describe --always --dirty --long --tags git log --pretty=format:'%H %ai'
-
Update the version number in the package.json file.
4. Windows
4.1. Installation
-
See http://blog.davidegrayson.com/2013/04/git-and-putty-in-windows.html.
-
Download the latest stable release from http://git-scm.com/downloads.
-
Run the Git-2.53.0-64-bit.exe file with administrative privileges.
-
Click Next.
C:\Program Files\Git
-
Click Next.
-
Uncheck * Windows Explorer integration*.
□ Additional icons □ On the Desktop ■ Windows Explorer integration ■ Open Git Bash Here ■ Open Git GUI Here ■ Git LFS (Large File Support) ■ Associate .git* configuration files with the default text editor ■ Associate .sh files to be run with Bash □ Check daily for Git for Windows updates □ Add a Git Bash Profile to Windows Terminal ■ Scalar (Git add-on to manage large-scale repositories)
-
Click Next.
-
Click Next.
Use Vim (the ubiquitous text editor) as Git's default editor
-
Click Next.
● Let Git decide ○ Override the default branch name for new repositories main
-
Click Next.
○ Use Git from Git Bash only ● Git from the command line and also from 3rd-party software ○ Use Git and optional Unix tools from the Command Prompt
-
Click Next.
-
Choose Use external OpenSSH.
○ Use bundled OpenSSH ○ Use (Tortoise)Plink ● Use external OpenSSH
-
Click Next.
○ Use the OpenSSL library ● Use the native Windows Secure Channel library
-
Click Next.
-
Choose Checkout as-is, commit as-is.
○ Checkout Windows-style, commit Unix-style line endings ○ Checkout as-is, commit Unix-style line endings ● Checkout as-is, commit as-is
-
Click Next.
-
Choose Use Windows' default console window.
○ Use MinTTY (the default terminal of MSYS2) ● Use Windows' default console window
-
Click Next.
● Fast-forward or merge ○ Rebase ○ Only ever fast-forward
-
Click Next.
-
Choose None.
○ Git Credential Manager ● None
-
Click Next.
-
Check Enable symbolic links.
■ Enable file system caching ■ Enable symbolic links
-
Click Install.
-
Uncheck View Release Notes.
□ Launch Git Bash □ View Release Notes
-
Click Finish.
-
Select Start > Programs > Git > Git CMD.
where git git --version exit
4.2. Configuration
-
Open Control Panel > System.
-
Select Advanced system settings.
-
Select the Advanced tab.
-
Click Environment Variables.
-
Click New in the System variables panel.
Variable name: OPENSSL_CONF Variable value: C:\Program Files\Git\mingw64\etc\ssl\openssl.cnf
-
Click OK.
-
Click OK.
-
Click OK.
-
Close System.
-
Add aliases for git in Command Prompt.
doskey.exe git-diff = git difftool -x "/usr/bin/diff" -y doskey.exe git-diff-c = git difftool -x "/usr/bin/diff --color" -y doskey.exe git-diff-i = git difftool -x "/usr/bin/diff -i" -y doskey.exe git-diff-w = git difftool -x "/usr/bin/diff -w" -y doskey.exe git-diff-iw = git difftool -x "/usr/bin/diff -iw" -y doskey.exe git-incoming = git fetch && git log ..origin doskey.exe git-log = git log --pretty=format:"%C(yellow)Commit %h%Creset%nAuthor: %an <%ae>%nDate: %ai%nMessage: %s%n" doskey.exe git-outgoing = git fetch && git log origin.. doskey.exe git-status = git status -s
git config core.autocrlf false # .git/config git config --global core.autocrlf false # C:/Users/<User>/.gitconfig git config --system core.autocrlf false # C:/Program Files/Git/etc/gitconfig # Requires administrative privileges. git config --list # .git/config git config --global --list # C:/Users/<User>/.gitconfig git config --system --list # C:/Program Files/Git/etc/gitconfig git config --list --show-origin
4.3. Usage
git clone -b development https://smru-it@bitbucket.org/madhums/NeoCom-Mobile.git git clone https://smru-it@bitbucket.org/madhums/NeoCom.git cd NeoCom git log | more git branch git branch -r git branch -a git tag -l git remote -v update git status git pull git diff
4.4. Usage of branches with Git
git branch test git checkout test git branch -a git status git commit -a git checkout master git status
4.5. Initialization of new Bitbucket repository
-
Create a new git repository at bitbucket.org.
mkdir D:\Bitbucket\Git\smru cd /d D:\Bitbucket\Git\smru git clone https://smru-it@bitbucket.org/smru/NeoCom-Config.git git clone https://smru-it@bitbucket.org/smru/NeoCom-Device.git cd ~/bitbucket/git/smru/NeoCom-Config cp -a ../../madhums/NeoCom/* . cp -a ../../madhums/NeoCom/.gitignore . git status git add . git status git commit -m "first commit" git push -u origin master cd ~/bitbucket/git/smru/NeoCom-Device cp -a ../../madhums/NeoCom-Mobile/* . cp -a ../../madhums/NeoCom-Mobile/.gitignore . git status git add . git status git commit -m "first commit" git push -u origin master
5. Import
| Old Bitbucket repository | Type | New GitHub repository | Match authors |
|---|---|---|---|
anc-app |
hg |
ANC-Application |
|
anc-application |
git |
ANC-Application-Heroku |
- |
database |
hg |
Database |
SMRU IT |
fingerprint |
git |
PMS-Application |
- |
public |
hg |
Documentation |
SMRU IT |
public |
hg |
Scripts |
SMRU IT |
neo-com |
hg |
NeoCom |
|
neocom-config |
git |
NeoCom-Config |
- |
neocom-device |
git |
NeoCom-Device |
- |
unix |
hg |
Unix |
SMRU IT |
windows |
hg |
Windows |
SMRU IT |
-
Sign in as smru on https://github.com/login.
-
Select + > Import repository
-
Type
https://smru-it@bitbucket.org/smru/<old repo>for the Your old repository’s clone URL. -
Type
<new repo>for the repository name. -
Choose Private.
-
Click Begin import.
-
Wait some time.
-
Type
smru-itfor the Bitbucket user name. -
Type the Bitbucket password.
-
Click Submit.
-
Wait some time.
-
Optional: Click Match authors.
-
Click <Author> > Connect.
-
Click Back to import.
-
cd ~delta/github/git/delta-software-labs
git clone https://delta-software-labs@github.com/delta-software-labs/ANC-Application.git
git clone https://delta-software-labs@github.com/delta-software-labs/ANC-Application-Heroku.git
git clone https://delta-software-labs@github.com/delta-software-labs/Database.git
git clone https://delta-software-labs@github.com/delta-software-labs/Documentation.git
git clone https://delta-software-labs@github.com/delta-software-labs/NeoCom.git
git clone https://delta-software-labs@github.com/delta-software-labs/NeoCom-Config.git
git clone https://delta-software-labs@github.com/delta-software-labs/NeoCom-Device.git
git clone https://delta-software-labs@github.com/delta-software-labs/PMS-Application.git
git clone https://delta-software-labs@github.com/delta-software-labs/Linux-Tools.git
git clone https://delta-software-labs@github.com/delta-software-labs/Windows-Tools.git
cd
ln -s ~/github/git/delta-software-labs/Documentation Documentation
ln -s ~/github/git/delta-software-labs/Linux-Tools Linux-Tools
ln -s ~/github/git/delta-software-labs/Windows-Tools Windows-Tools
cd Documentation
cd
mkdir -p gitlab/git/delta/<repo-name>
mkdir -p gitlab/git/dhkiestra/GitLabExercise
ln -s ~/gitlab/git/delta/<repo-name> <repo-name>
ln -s ~/gitlab/git/dhkiestra/GitLabExercise GitLabExercise
cd GitLabExercise
6. Git Credential Manager
-
Install Git Credential Manager.
-
Install Git for Windows to prevent the following error.
Unhandled Exception: System.Exception: Failed to locate 'git.exe' executable on the path.
6.1. Configuration
6.1.1. WSL
-
Note: Only works for the first account set up during installation of the WSL instance. It doesn’t work for other accounts that are created later, and the following error is shown.
/mnt/c/Program Files/Git Credential Manager/git-credential-manager.exe: Invalid argument
-
Note: This seems to be an ongoing WSL issue. Typing explorer.exe at the command line from any directory using the first user account works. However, typing explorer.exe at the command line using any other (later created) account only works from the home directory.
-
Enter the following commands at a Command Line.
git config --global credential.helper '/mnt/c/Program\ Files/Git\ Credential\ Manager/git-credential-manager.exe' git config --list --show-origin -
Contents of the ~/.gitconfig file.
[color] color = always [core] autocrlf = false [push] default = simple [user] name = Douwe Kiestra email = douwe@deltasoftware.frl [credential] helper = /mnt/c/Program\\ Files/Git\\ Credential\\ Manager/git-credential-manager.exe