Git
Instalação, configuração e uso do git via linha de comando
Instalação, configuração e uso do git via linha de comando.
Instalação e configuração do PortableGit com token de acesso
Instalação e configuração do PortableGit com token de acesso
Uso do git no VScode
Uso do Git e GitHub no STM32CubeIDE
Uso do Git e GitHub no STM32CubeIDE
Git commands
git --version
How to config git
git config --global user.name "Your Name"
git config --global user.email yourmail@domain.tld
It's recommended to verify that the your Git installation is not performing any transformation between LFs and CRLFs.
git config --global core.autocrlf false
git config --global color.ui auto
git config --global init.defaultBranch main
Configure Git to use Visual Studio Code (VS Code) as the default editor for tasks like writing commit messages or interactive rebases
git config --global core.editor "code --wait"
git config --global -e
git config list --show-origin
Git Cheat Sheet
Git is a free and open-source distributed version control system that is responsible for everything that happens locally on your computer that is related to GitHub. This cheat sheet contains the most important and common Git commands for easy reference.
Installation & GUIs
GitHub offers platform-specific installers for Git, which also provide a graphical user interface for daily interaction, review, and repository synchronization.
Setup
You can configure user information that will be used across all local repositories.
git config --global user.name "[firstname lastname]"
: This sets a name that provides credit when reviewing version history.git config --global user.email "[valid-email]"
: This sets an email address that will be linked with each history marker.git config --global color.ui auto
: This sets up automatic command-line coloring for Git, making it easier to review.
Setup & Init
This section covers configuring user information as well as initializing and cloning repositories.
git init
: Initializes an existing directory as a Git repository.git clone [url]
: Retrieves an entire repository from a hosted location using a URL.
Stage & Snapshot
These commands are used for working with snapshots and the Git staging area.
git status
: Shows modified files in the working directory that are staged for your next commit.git add [file]
: Adds a file, as it currently appears, to your next commit.git reset [file]
: Unstages a file but keeps the changes in the working directory.git diff
: Shows the differences of what has been changed but not yet staged.git diff --staged
: Shows the differences of what has been staged but not yet committed.git commit -m "[descriptive message]"
: Commits your staged content as a new commit snapshot.
Branch & Merge
These commands are for isolating work in branches, changing context, and integrating changes.
git branch
: Lists your branches. An asterisk*
will appear next to the active branch.git branch [branch-name]
: Creates a new branch at the current commit.git checkout [branch-name]
: Switches to a different branch and checks it out into your working directory.git merge [branch]
: Merges the history of the specified branch into your current branch.git log
: Shows all commits in the history of the current branch.
Inspect & Compare
These commands are used for examining logs, diffs, and object information.
git log
: Shows the commit history for the currently active branch.git log branchB..branchA
: Shows commits that are onbranchA
but not onbranchB
.git log --follow [file]
: Shows the commits that changed a specific file, even if it was renamed.git diff branchB...branchA
: Shows the diff of what is inbranchA
but not inbranchB
.git show [SHA]
: Shows any object in Git in a human-readable format.
Tracking Path Changes
This section covers versioning file removals and path changes.
git rm [file]
: Deletes a file from the project and stages the removal for a commit.git mv [existing-path] [new-path]
: Changes an existing file's path and stages the move.git log --stat -M
: Shows all commit logs and indicates any paths that were moved.
Ignoring Patterns
These commands are for preventing files from being unintentionally staged or committed.
git config --global core.excludesfile [file]
: Creates a system-wide ignore pattern for all local repositories.- You can save a file with desired patterns, using either direct string matches or wildcard globs, as
.gitignore
. Some examples of patterns areLogs/
,*.notes
, andpattern*/
Share & Update
These commands are for retrieving updates from another repository and updating local repositories.
git remote add [alias] [url]
: Adds a Git URL as an alias.git fetch [alias]
: Fetches all branches from the specified Git remote.git merge [alias]/[branch]
: Merges a remote branch into your current branch to bring it up to date.git push [alias] [branch]
: Transmits local branch commits to the remote repository branch.git pull
: Fetches and merges any commits from the tracking remote branch.
Rewrite History
This section is about rewriting branches, updating commits, and clearing history.
git rebase [branch]
: Applies any commits from the current branch ahead of the specified one.git reset --hard [commit]
: Clears the staging area and rewrites the working tree from the specified commit.
Temporary Commits
These commands temporarily store modified, tracked files so you can switch branches.
git stash
: Saves modified and staged changes.git stash list
: Lists the stack-order of stashed file changes.git stash pop
: Writes a working file from the top of the stash stack.git stash drop
: Discards changes from the top of the stash stack.
GitHub Education
GitHub is free for students and teachers, and discounts are available for other educational uses.
Reference
- Try Github - https://try.github.io
- Pro Git - Free Book - http://git-scm.com/book