Skip to content

Latest commit

 

History

History
75 lines (47 loc) · 2.25 KB

git-config.md

File metadata and controls

75 lines (47 loc) · 2.25 KB

Configuring Git Aliases and User Settings

Git aliases can significantly improve your workflow by providing shorthand commands for frequently used operations. Below is a step-by-step guide to configure Git aliases and set your Git user name and email.

Setting Git User Name and Email

It's essential to set your Git user name and email globally so that commits are properly attributed to you.

Steps to Configure User Name and Email

  1. Open your terminal and run the following commands:

    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
  2. Verify the configuration:

    git config --global --list

    You should see your name and email listed in the output.


Setting Up Git Aliases

Add the following aliases to your Git configuration to speed up common tasks:

[alias]
  s = !git status -s
  c = !git add --all && git commit -m
  co = !git checkout
  l = !git log --pretty=format:'%C(blue)%h%C(red)%d %C(white)%s - %C(cyan)%cn, %C(green)%cr'
  set = !git push --set-upstream origin "$(git symbolic-ref --short HEAD)"
  newMaster = !git branch -D master && git checkout master && git pull && git checkout -b
  newMain = !git branch -D main && git checkout main && git pull && git checkout -b

How to Add These Aliases

  1. Open the Git configuration file in your editor:

    git config --global --edit
  2. Copy and paste the alias block above under the [alias] section.

  3. Save and close the file.

Now you can use these aliases directly in your terminal, e.g., git s for a short status or git c "Commit message" to stage all changes and commit them with a single command.


Additional Notes

  • Global vs Local Configuration: The --global flag applies the configuration to all repositories on your machine. To set these settings for a specific repository, omit the --global flag and run the commands in the repository's directory.

  • Editing Configuration Directly: You can edit the global configuration file manually:

    nano ~/.gitconfig

This file contains all your global settings, including aliases and user information.


With these steps, you'll have a more efficient Git workflow and properly attributed commits!