-
Notifications
You must be signed in to change notification settings - Fork 0
Cygwin
Download and run the installer. If you are not an admin on your machine, you should install Cygwin with the --no-admin
option, and in your user directory (so other users don't see your settings and private keys).
Install apt-cyg, which allows managing packages from the command line:
lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
install apt-cyg /bin
The latest Cygwin version reads Active Directory for user/group permissions. If Cygwin takes a long time to start up (5+ minutes), that's a possible cause. We can set Cygwin to read from files instead:
Save user/group permissions to files:
mkpasswd -c > /etc/passwd
mkgroup -c > /etc/group
Open /etc/nsswitch.conf and add:
passwd: files
group: files
Restart Cygwin.
Now to the good part.
apt-cyg install bash-completion
apt-cyg install git
apt-cyg install git-completion
git config --global user.name "[First Last]"
git config --global user.email "[email]"
Keep your line endings sane. Consider adding a .gitattributes file to your repository as well.
git config --global core.filemode false
git config --global core.autocrlf true
You can have the bash prompt show your Git context: what branch you are on, how many commits you are ahead/behind the remote branch, if you have changed/staged files, etc.
You will need git-prompt.sh. Then add this to .bashrc
:
# https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
source ~/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[01;33m\]$(__git_ps1)\[\033[01;34m\] \$\[\033[00m\] '
Not required, customize to your liking. The goal in life is less typing.
git config --global alias.b branch
git config --global alias.co checkout
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.cm "commit -m"
git config --global alias.cam "commit -am"
git config --global alias.amend "commit --amend"
git config --global alias.lg "log --decorate --oneline --stat --graph"
git config --global alias.lg2 "log --decorate --graph --date=relative --all"
git config --global alias.f "fetch -p"
Does Git complain that permissions for your private key (default at ~/.ssh/id_rsa) are too open?
Let Cygwin own the file, otherwise you cannot change its permissions. Note that "Users" may or may not be the default group for Cygwin. You can run mkgroup -c to find out.
chgrp Users ~/.ssh/id_rsa
Set the private key to be editable by only you! ❤️
chmod 600 ~/.ssh/id_rsa
Not that I have any.
Basically, create keys with specific emails, then use SSH config file to map them to remotes.
Use ssh-copy-id
to copy the public key to the remote server.
This also opens up the very interesting concept of further segmenting your github keys on something like a per-project or per-organization basis:
# ~/.ssh/config Host github-project1 User git HostName github.com IdentityFile ~/.ssh/github.project1.key</p> Host github-org User git HostName github.com IdentityFile ~/.ssh/github.org.key</p> Host github.com User git IdentityFile ~/.ssh/github.key
Which means that if I want to clone a repository using my organization credentials, I would use the following:
git clone git@github-org:orgname/some_repository.git