Git

Git commands

  • git --version Version de git

  • git config --global core.autocrlf true To avoid uploading the Carriage Return character, true for windows and input for mac/linux

  • git remote -v View existing remotes repos

  • git remote add origin <url> Set a remote url origin

  • git add <files or '.'> Add new files to be tracked by git or add changes to staging area

  • git commit -m '<message>' Commited the existing changes in the staging area

  • git commit -am '<message>' Add changes to tracked files and then commited them at the same time

  • git rm <file> Delete tracked files in local and recorded in staging area

  • git rm --force <file> Delete tracked files in local and hard disk

  • rm <file> Delete untracked files

  • git restore --staged <file> Remove files to unstage

  • git restore <file> To discard changes in working directory

  • git reset HEAD <file> Remove files from staging area . (dot)

  • git checkout <file> Remove files from staging area or . (dot)

  • git stash takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy, Adding the -u option (or --include-untracked) tells git stash to also stash your untracked files

  • git stash save "<message>" To provide a bit moqre context

  • git stash list To view your commits to the git stash history

  • git stash takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy

  • git stash pop will re-apply the most recently created stash: stash@{0}, you can choose which stash to re-apply by passing its identifier as the last argument git stash pop stash@{2}

  • git stash clear Delete all of your stashes, git stash drop stash@{1} delete a particular stash

  • git blame Dqisplay of author metadata attached to specific committed lines in a file

  • git commit --amend --no-edit Edit the last commit with prompt, (use esc+shift+z+z to save)

  • git commit --amend --no-edit Edit the last commit, useful when you forget to stage a file or to format your commit message the wrong way.

  • git log --all --decorate --oneline --graph Shows all commits and graph

  • git config --global alias.[name] '<command>' Create alias for a list of commands

Undoing Commits & Changes

  • git checkout Command to visit any commit or change the branch, also works by file (You can get a file from old commit to the present, then add and coomit again)

  • git checkout -b <name branch> This will create a new branch from any branch or commit where the HEAD is named and switch to that state

  • git reset --soft [SHA 1]: Remove changes to staging area, last commit HEAD~1

  • git reset --mixed [SHA 1]: Remove changes to working area

  • git reset --hard [SHA 1]: Reset changes to commit of [SHA-1], (needs --force when pushed the branch), also used for unmerge changes git reset --hard HEAD~1 git pull origin <branch>

  • git revert [SHA 1] Useful to undo commits in a public branch, use --no-edit for avoid many messages

Reset Branch al repositorio remoto

git fetch origin
git reset --hard origin/<branch>

Git merge

Merge without commit

git merge <branch> --no-commit

Last updated