Setting up git
in your device
git config --global user.name <your-username>
git config --global user.email <your-email>
git config --global user.signingKey <keyID>
--global
: The configuration applies to all repositories for the current user.--local
: The configuration applies only to the current repository.--system
: The configuration applies to all users on the system.
user.name
&user.email
define the author’s identity for commits.
user.signingKey
specifies the GPG key ID used for signing commits and tags.
To display all the current configurations:
git config --list
To display the specific configurations:
git config --global user.name
git config --global user.email
Enable commit signing:
git config --global commit.gpgSign true
After enabling this, every commit will be automatically signed without needing the -S
flag.
Disable commit signing:
git config --global --unset commit.gpgSign
General Use Cases:
- Staging the changes:
git add filename.ext
-A
will select all the changes in the current directory. (Not a good practice, unless you know what you are doing)-i
for interactive picking the changes. (Useful for handling large changes)
- Committing the changes:
git commit -S -am "commit message"
-S
- Signs the commit with your GPG key.-a
- Stages all modified and deleted tracked files (but not new files).-m
- Allows entering the commit message inline.
- Pushing the Changes:
git push <remote> <branch>
<remote>
- The name of the remote repository (e.g.,origin
).
# find the remote repository name by
git remote -v
<branch
> - The name of the branch to push (e.g.,main
orfeature-branch
).
# find the available or current branch by
git branch
- Show the commits:
git log --oneline --decorate --graph
--oneline
- shows the commit in single line without any verbose output.--decorate
- use pretty printing (with colors!)--graph
- displays the commit messages in graph format. (easily understandable)