Cannot create simple Git alias in MinGW32 on windows 7 - windows

I am trying to create a very simple alias. I want alias the following command:
git log --oneline --graph --all -- decorate
I find this command a very useful way to view the log file. I want to alias this line as git l because its the main way I wish to view the log file. This is my attempt to create the alias:
git config --global alias .l "git log --oneline --graph --all -- decorate"
This line executes without error, but then any attempt to call git l results in the following error message.
Expansion of alias 'l' failed; 'git' is not a git command
It was explained that working environment, windows 7, minGW32, and git version 1.8.3.msysgit.0 could have something to do with this issue, but I am not sure how to resolve this. Thank you to anyone who helps out.

It should be:
git config --global alias.l "log --oneline --graph --all --decorate"
To call something other than a git command, you would prefix it with an exclamation point:
git config --global alias.foo "!foo --do-something"
In your case, it could've been:
git config --global alias.l "!git log --oneline --graph --all --decorate"

Related

Command: git hist ERROR. fatal: option '--graph' must come before non-option arguments

I am trying to run git hist cmd on GitBash, Windows but I am getting the following error
fatal: option '--graph' must come before non-option arguments
On window PowerShell, I entered:
git config --global alias.hist log --pretty=format: '%h %ad | %s%d [%an]' --graph --date= short"
But still getting the same error.
Please can I know why and how can avoid this error?
Simply move the --graph / --date options first.
I just tested, from a regular CMD (no PowerShell needed):
git config --global alias.hist "log --graph --date=short --pretty=format:'%h %ad | %s%d [%an]'"
Then git hist works just fine.
Note the lack of space between format: and '%h...'

Git alias to open the git installation folder

I want to create a git alias git dir, which when used should open the git installation folder via Windows Explorer, how to implement such an alias?
If using Git Bash, try:
git config --global alias.dir '!start "" "$(git --exec-path)"'
Reference: Can I use the "start" command with spaces in the path?
Starting an alias with ! treats it as a command.
I don't have a windows machine at hand, but for Linux:
git config --global alias.open '!git --exec-path | xargs xdg-open'
Works as described.
So the command you're looking for will probably look something like:
git config --global alias.open "!git --exec-path | 'sed s~/~\\~g' | xargs explorer"

Creating git aliases

I am trying to add the following aliases in ubuntu
alias l=log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
$ source ~/.aliases
bash: alias: --decorate: not found
bash: alias: --decorate: not found
bash: alias: --numstat: not found
I could use this command outside with git
I am not so sure why? Can someone help me? I tried googling but I did not go far with it. I do not know bash so much.
This is bit older question but it is very important to understand and create git alias as this will save lot of time of yours.
In your question you are close to answer just a silly mistake done is you are trying to create alias using script.
Alias needs to be defined in .gitconfig file. Not just alias but all config part like
[core], [color], [pack], [help], [alias] etc
I would like to share some basic and useful alias with you to have things handy and you can change it further per your need and daily usage
[alias]
lg = log -p
lol = log --graph --decorate --pretty=oneline --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
st = status
co = checkout
ci = commit -a -m
br = branch
ls = ls-files
po = push origin
f = fetch
p = pull
delete = branch -d master
com = checkout master
cob = checkout -b
unstage = reset HEAD
url = remote set-url origin
ign = ls-files -o -i --exclude-standard
cp = cherry-pick
You can also create an alias for a combination of multiple git commands in a single one as, for instance:
rdev = !git checkout dev && git pull && git checkout - && git rebase dev
Let me know if any other understanding needed.
You are almost there. You just need to put the alias in the right file. Because Git doesn’t automatically infer your command if you type it in partially, you can easily set up an alias for each command using git config like so:
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
And then you use it the aliases like: git ci, git co, git br, git st in any repo.
You can also run an external command through an alias. In that case, you start the command with a ! character. This is useful if you write your own tools that work with a Git repository:
git config --global alias.visual '!gitk'
You might have also noticed that the config command takes in several parameters (like the --global one). If we look at the docs man git config:
For writing options: write to global ~/.gitconfig file rather than the repository .git/config, write to $XDG_CONFIG_HOME/git/config file if this file exists and the ~/.gitconfig file doesn’t.
For reading options: read only from global ~/.gitconfig and from $XDG_CONFIG_HOME/git/config rather than from all available files.
See also the section called “FILES”.
There is also --system, which writes to /etc/gitconfig, --local, for the local repo .git/gitconfig, and --worktree, which is similar to --local.
But you can just directly edit the files themselves. It will look similar to this:
# in ~/.gitconfig
[alias]
lg = log --all --stat --pretty=oneline --graph --format='%h %d %an %cr %s' --oneline
l = log --all --stat --graph --format='%h %d %an %cr %s'
up = pull --rebase
br = branch --verbose -a
sfp = push --force-with-lease
You should set the alias in your git aliases and use it from the command line
You can directly edit the configuration file or do it from CLI:
Git Alias
Use the git config --global alias.<name> in order to add git alias
git config --global alias.l 'log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate'
now you should be able to use it with: git l
Ubuntu Alias
If you wish to add an alias to your shell in Ubuntu:
alias gitl='git l'

Add new command on Windows Git Bash

I would like to add new command on my Git Bash (just now i am under Windows OS). I tryed to look on Web different solutions but I did not find anything. The command that i like to add is:
commitall -> git add --all && git commit -m "$*"
There is a way to add this command on Windows Git Bash?
Thanks
Use Git aliases, like so:
git config --global alias.commitall '!git add --all && git commit -m'
There's no need to use $* because all the arguments you specify will simply be appended to the line above, i.e. if you run:
git comitall "a message"
…the following will be executed:
git add --all && git commit -m "a message"

How can I edit my Git config?

I feel like this issue has been addressed before, but I couldn't find it after search through a bunch of posts.
I am doing a beginner's tutorial on Git. Someone had this Mac before me and used multiple Git Applications (SourceTree, etc) that seem to have added all kinds of config preferences.
When I type git config --list, I get an enormous list (shown below), unlike the tutorial that I am watching on Lynda.com where the author only shows a list of user.name and user.email.
core.excludesfile=~/.gitignore
core.legacyheaders=false
core.quotepath=false
core.pager=less -r
mergetool.keepbackup=true
push.default=simple
color.ui=auto
color.interactive=auto
repack.usedeltabaseoffset=true
alias.s=status
alias.a=!git add . && git status
alias.au=!git add -u . && git status
alias.aa=!git add . && git add -u . && git status
alias.c=commit
alias.cm=commit -m
alias.ca=commit --amend
alias.ac=!git add . && git commit
alias.acm=!git add . && git commit -m
alias.l=log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
alias.ll=log --stat --abbrev-commit
alias.lg=log --color --graph --pretty=format:'%C(bold white)%h%Creset -%C(bold green)%d%Creset %s %C(bold green)(%cr)%Creset %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
alias.llg=log --color --graph --pretty=format:'%C(bold white)%H %d%Creset%n%s%n%+b%C(bold blue)%an <%ae>%Creset %C(bold green)%cr (%ci)' --abbrev-commit
alias.d=diff
alias.master=checkout master
alias.spull=svn rebase
alias.spush=svn dcommit
alias.alias=!git config --list | grep 'alias\.' | sed 's/alias\.\([^=]*\)=\(.*\)/\1\ => \2/' | sort
include.path=~/.gitcinclude
include.path=.githubconfig
include.path=.gitcredential
diff.exif.textconv=exif
credential.helper=osxkeychain
mergetool.sourcetree.cmd=--null
user.name=username
user.email=email
Ultimately, I would like to remove all of these additional settings. I tried uninstalling Git, but that didn't make a difference. Is there a command to undo all of these? Any help would be appreciated.
Your Git configuration is spread across up to three config files (one for each level).
You can edit your config (add/remove entries) by editing those files, or by using the right git-config commands (more robust, but possibly more tedious). The problem is simply to locate which part of your config is located in which config file. Instead of running
git config --list
which lists the contents of all three files (i.e. your entire Git configuration), you can run three different commands for listing the contents of each of those three config files.
System-level config file
Usually located at /usr/local/etc/gitconfig; at least, that's where mine is on my Mac (I installed Git with Homebrew). You can list its contents by running:
git config --system --list
User-level config file
Usually located at $HOME/.gitconfig. You can list its contents by running:
git config --global --list
Repository-level config file
Usually located at <repo-root-folder>/.git/config. You can list its contents by running:
git config --local --list
If you only want to retain the user.name and user.email fields from your current config and get rid of all the rest, the easiest thing is to delete all three config files and then simply run
git config --global user.name <your-name>
git config --global user.email <your-email>
(The user.name and user.email fields are most commonly set in the user-level config file.)

Resources