Skip to content

Git commands that have proven to be very useful for me

Notifications You must be signed in to change notification settings

manuelaguadomtz/git-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 

Repository files navigation

Git cheatsheet

Git commands that have proven to be very useful for developers

Configurations

Set the global username

git config --global user.name "John Doe"

Set the global user email

git config --global user.mail "[email protected]"

Set the local username

git config --local user.name "John Doe"

Set the local user email

git config --local user.mail "[email protected]"

To unset a given configuration

git config --global --unset-all user.name

To list global configurations

git config --global --list

To replace configurations

git config --global --replace-all user.name "New User Name"

To ignore file mode changes (i.e file permissions)

git config core.fileMode false

To ignore new line character differences between systems (windows-linux)

git config --global core.autocrlf true

To configure a proxy server

git config --global http.proxy http://proxyuser:[email protected]:proxy_port

To store credentials

git config --global credential.helper store

Working with remotes

List all the configured remote repositories

git remote -v

Remove a remote server

git remote rm <remote>

Working with Branches

To push all your branches

git push <remote> --all

List all the branches

git branch

List all the branches (local and remote branches)

git branch --all

Make a switch to a specified branch

git checkout <branch>

Deleting specified branch

git branch -d <branch>

Tracking a remote branch

git branch -u <remote>/<branch>

To remove all the remote tracking branches that no longer exists

git remote prune <remote>

To remove an specific remote tracking branch

git branch -d -r <remote>/<branch>

To remove a remote branch

git push <remote> --delete <branch>
git push <remote> :<branch>

Tagging

Pushing tags to the remote

git push <remote> --tags

Pushing commits and also tags to the remote

git push --follow-tags

Removing a local tag

git tag -d <tag-name>

Removing a remote tag

git push --delete <remote> tagName

Reverting to previous states

Reverting Files

Showing file snapshot at specific commit

git show <commit-sha>:relative/path/to/file/inside/repo

Saving file snapshot at specific commit

git show <commit-sha>:relative/path/to/file/inside/repo > /new/path/to/file/content/at/selected/commit

Graph history visualization

Showing last commit

git log -1 

Showing the current local history (-5 last five commits)

git log --decorate --graph -5

Showing commits by a specific user

git show git log --author=bob | grep ^commit | awk -F ' ' '{print $2}'

About

Git commands that have proven to be very useful for me

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published