To install Git, run pacman -S git
in an MSYS2 terminal. Set
up the commit author information with the following commands.
git config --global user.name "Your Name" git config --global user.email "email@example.com"
The following configuration commands are also recommended.
This configures rebasing by default instead of merging when pulling a branch.
git config --global branch.autosetuprebase always
This enables 3-way diffs during merge conflicts. This gives context for both changes from a common base, which is much easier to resolve.
git config --global merge.conflictstyle diff3
This enforces fast-forward merges, effectively disallowing merge commits (they clutter up history).
git config --global merge.ff only
This disables auto-conversions of line endings to CRLF on Windows, which avoids entire files showing as conflicting during merge conflicts when the files have differing line endings between two branches.
git config --global core.autocrlf false
In general, Git tries to be helpful. If you don't know what to do after running a Git command or seeing something fail, read the text Git prints for possible hints or instructions.
main
is considered the stable branch which contains tested,
working code. Work on features and bugfixes should occur on separate
branches. Users should make as many commits on experimental branches as
they feel is necessary. Before a branch is merged with main
,
intermediate commits are typically squashed to produce one or several
feature, bugfix, or cleanup commits.
git clone <repository> [<directory>]
This downloads the repository at the given URL to the current directory.
<directory>
overrides the name of the repository's
containing folder.
example: git clone
https://github.com/frc3512/DriverStationDisplay
example: git clone
git@github.com:frc3512/DriverStationDisplay
git add <file>
This adds new, untracked files as well as changes to already tracked ones.
example: git add Main.cpp
git rm [--cached] <file>
This deletes and stops files from being tracked. If the
--cached
option is provided, it only removes the specified
files' changes from the staging area.
example: git rm UnneededFile.hpp
example: git rm --cached Main.cpp
git commit [-m "commit message"]
This commits changes currently in the staging area. If git
commit
is called without the -m option
, an editor will
be opened for entering a commit message.
example: git commit -m "Adding new feature x"
git push [<branchname>]
This pushes commits from a branch to the corresponding branch on a
remote repository. If <branchname>
isn't specified, Git
will use the currently checked out branch.
example: git push my-branch
git pull --rebase [<refspec>]
This pulls the ref <refspec>
(a branch, commmit, or
tag) from the remote repository and rebases it into the current branch. If
<refspec>
isn't specified, Git will attempt to pull
changes from a remote branch with the same name as the currently checked
out branch.
example: git pull origin/main
git branch <branchname>
This creates a new branch starting at the current commit. Omitting
<branchname>
shows a list of all branches and an
asterisk beside the current one.
example: git branch new-feature
git branch -d <branchname>
This deletes the branch <branchname>
. This command
won't work if that branch is currently checked out.
example: git branch -d merged-feature
git switch <branchname>
This checks out <branchname>
. The default branch when
a new project is created is called main
.
example: git switch other-branch
git merge <branchname>
This merges commits from the specified branch into the branch currently checked out. In some cases, one may want to delete the branch after merging it (see 8).
example: git merge new-feature