Skip to content

This document contains my own documentation on Git and Github.

License

Notifications You must be signed in to change notification settings

lbrealdev/le-git

Repository files navigation

le-git

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

git status

Show the working tree status:

git status

Show the branch and tracking info in short-format:

git status -bs

git branch

Show the current branch context:

git branch

List both remote-tracking and local branches:

git branch -a

List branch names:

git branch -l

Create a branch

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

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>

git checkout

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 -

git config

List your global git configuration:

git config --global -l

List your local git configuration:

git config --local -l

global config repositories

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@example.com"

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

single config repository

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@example.com"

Confirm that you have set the Git username correctly single repository:

git config user.email

Edit single repository config:

git config --edit

git add

Add files:

git add .

Add files recursively:

git add -A

git rm

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>

git remote

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

git log

Show commit logs with pretty output:

git log --oneline

Get the hash of the last commit:

git log -1 --format="%H"

git commit

Empty commit

Empty commit to trigger CI via github actions:

git commit --allow-empty -m "actions: trigger CI"

Push empty commit to activate CI:

git push

Undo a commit

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

About

This document contains my own documentation on Git and Github.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages