This document contains le-git (legit)
that means "Let's Explain Git and Github". This is my own public documentation about git and github where I make random updates to one topic or another about the two tools
Show the working tree status:
git status
Show the branch and tracking info in short-format:
git status -bs
Show the current branch context:
git branch
List both remote-tracking and local branches:
git branch -a
List branch names:
git branch -l
To create a new branch and switch to it at same time, run the following command:
git checkout -b <branch-name>
Once the new branch is created, push it:
git push -u origin <branch-name>
Delete a branch remotely:
git push -d origin <branch-name>
Once the branch has been deleted remotely, delete it locally:
git branch -D <branch-name>
Switch branch:
git checkout <branch-name>
Switch branch even if the index or the working tree differs from HEAD
:
git checkout -f <branch-name>
Switch to main
branch:
git checkout -
List your global git
configuration:
git config --global -l
List your local git
configuration:
git config --local -l
Setting your Git username for every repository on your computer:
git config --global user.name "Your Name"
Confirm that you have set the Git username correctly global config
:
git config --global user.name
Setting your email address for every repository on your computer:
git config --global user.email "[email protected]"
Confirm that you have set the email address correctly in Git global config
:
git config --global user.email
Edit global repository config:
git config --global --edit
Setting your Git username for a single repository:
git config user.name "Your Name"
Confirm that you have set the Git username correctly single repository
:
git config user.name
Setting your email address for a single repository:
git config user.email "[email protected]"
Confirm that you have set the Git username correctly single repository
:
git config user.email
Edit single repository config:
git config --edit
Add files:
git add .
Add files recursively:
git add -A
Remove files from the working tree and from the index:
git rm -f <file>
Remove a directory from the working tree:
git rm -r <directory>
Show the location configured:
git remote -v
Update location:
git remote set-url origin <new-github-repo-url>
Deletes all stale remote-tracking branches:
git remote prune origin
Show commit logs with pretty output:
git log --oneline
Get the hash of the last commit:
git log -1 --format="%H"
Empty commit to trigger CI via github actions:
git commit --allow-empty -m "actions: trigger CI"
Push empty commit to activate CI:
git push
If you have not pushed your changes to remote, run follow steps:
List most recent commits with nice formatting to identify unwanted commits:
git log --oneline
Once identified, run this command to undo this commit:
git reset HEAD~1