GIT Vademecum
GIT is a distributed version control system that facilitates Mia-Platform activities. This cheat sheet summarizes the main GIT commands and provides some guidelines to simplify your work.
Install Git
Start using Git by installing it on your PC. Visit GIT official website and download the latest GIT version for your OS.
Initial configurations
Configure valid user information for all repositories.
git config --global user.name "[name]"
git config --global user.email "[email address]"
You can also set different user information for different repositories. Open the terminal in that directory and run the commands above without the --global
specification.
Recommended configurations
We recommend a series of configurations that can help you in your work.
git config --global fetch.prune true
git config --global pull.rebase true
git config --global rebase.autoStash true
git config --global alias.gr 'log --graph --full-history --all --color --tags --decorate --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s %x1b[33m%aN <%ae>%x1b[0m (%aI)"'
git config --global --add --bool push.autoSetupRemote true
The git config --global --add --bool push.autoSetupRemote true
configuration is available only for 2.37.0 (or latest) version of GIT.
Create a repository
Start with a new repository or download information from an existing URL.
git init [project-name]
git clone [url]
Make changes
Review changes to the code and prepare a commit.
git status
git diff
git add [file]
git diff --staged
git reset [file]
git commit -m "[descriptive message]"
git commit -s
git push
Manage the branch
Name your branches and join them when you finish.
git branch
git branch -b [branch-name]
git checkout [branch-name]
git merge [branch-name]
git branch -d [branch-name]
git push origin -d [branch-name]
Make refactoring your files
Search and remove files from the history.
git rm [file]
git rm --cached [file]
Remove your files from the history
Exclude files and temporary locations.
*.log build /TEMP-*
git ls-files --others --ignored --exclude-standard
Save all changes
Archive and restore incomplete changes. Useful for remotely downloading changes while you are working and you do not want to commit
and push
again or to change from one branch to another without committing before.
git stash
git stash pop
git stash list
git stash drop
Review the chronology
Browse and check the evolution of the files of each project.
git log
git log --follow [file]
git diff [first-branch] ... [second-branch]
git show [commit]
Re-commit
Delete errors and alters changes history.
git reset [commit]
git reset --hard [commit]
git commit --amend --signoff
Synchronize changes
Connect to a remote URL and get change history.
git fetch [remote]
git merge [remote] / [branch]
git push -u [remote] [branch]
git pull