-
To setup git properly use
git config
-
You can always edit the
~/.gitconfig
file for global configuration -
Edit the
.git/config
file for a per repository configuration -
Use the
--global
for setting up global configuration -
Use the
--local
for setting up local configuration -
To initialize a git repository
git init
-
Every command we use can change either the local or the global configuration depending on the flag
-
To view the current global configuration:
git config --global --list
- To view the current local configuration
git config --local --list
- To set configuration
git config --global --set alias.l1 "log --oneline -n 10"
-
With this set we can run
git l1
as if we were runninggit log --oneline -n 10
-
You can add this either in the
~/.gitconfig
or in the./.git/config
files depending if you want to do it globally or not
-
Git uses under the hood
less
to show its results, that makes that it paginates them, however you can disable -
Per command, always goes between the git and the command
git --no-pager log
- You can disable it by changing its default pager
git config --global --set core.pager cat
git add -p
- To rephrase your last commit
git commit --amend
- WARNING Do not amend your commit once pushed
git commit --trailer "Signed-off-by:C O Mitter \ <[email protected]>" --trailer "Helped-by:C O Mitter \ <[email protected]>"
git commit --allow-empty -m "Initial commit"
You can clone a remote repository into a Git Worktree configuration by running
git clone --bare https://github.com/chingu-voyages/roundtable-advanced-git.git
That will display all the git files that you usually see inside of the .git
directory, to add those to a hidden file we will need
to execute:
git clone --bare https://github.com/chingu-voyages/roundtable-advanced-git.git .bare
echo "gitdir: ./.bare" > .git
This will clone the repo into the .bare
directory and tell git that its configuration files are located inside the .bare
directory