Git
CLI Commands
-
git --version-
Shows the git version.
-
-
git \_generic_command -h-
Shows the help/tutorials for the given command; e.g.: git clean -h.
-
-
git init-
Initializes a git repository. If the directory doesn't have a
.gitfolder, it is created with files inside.
-
-
git remote add origin https://github.com/YOUR_USER/YOUR_REPO.git-
Add the remote repository to your local project.
-
-
git remote -v-
Check if the remote repository was added correctly.
-
-
git clone
git clone https://github.com/username/repo.git
git clone https://github.com/username/repo.git my-custom-folder
git clone git@github.com:username/repo.git -
git ls-a-
Shows all git files.
-
-
git ls-tree \_COMMIT_ID (or) \_HEAD~\_number_of_commits_to_go_back-
Shows the content in a 'tree' format of the given commit; if no commit is given, the current one is used.
-
-
git add \_file_name (or) \_abbreviations_for_multiple_files-
Adds the changes of the file(s) to the staging area.
-
-
git rm \_file_name-
Removes the file from the local directory and the staging area.
-
-
git commit -m "\_title"-
git commit -m "\_title" -m "\_description" -
Commits the changes that were in the staging area. The -m option is used to set the "_title" message for the commit.
-
Adds an extra description in addition to the initial "_title".
-
-
revert-
Creates a new commit that reverses the changes of the previous commit.
-
It's pretty safe.
-
-
git reset-
Moves HEAD "back", basically doing an UNDO of everything new that was done.
-
(2024-10-19) I used
git reset. It worked nicely. The commit is undone and the commit's changes are placed in the Changes tab to be committed again or discarded. -
Types of 'reset':
-
git reset==git reset HEAD -
git reset HEAD^-
HEAD^means "the parent commit" of the commit HEAD is pointing to (the commit before the most recent).
-
-
-
.
-
-
restore-
Restores the file to a previous version.
-
There are other options with
git restore -h. -
git restore \=\=source\=\_COMMIT_ID (or) \_HEAD~\_number_of_commits_to_go_back \_file_name
-
-
amend-
Combines the previous commit with the staged modifications.
-
Usually used only to change the commit message/description.
-
I tried to use this when there were file changes, and it resulted in creating a new branch, with a merge back to the current branch with the changes. It was kind of weird and not "clean".
-
-
cherry-pick-
Used to move individual commits between branches, commonly used to fix the mistake of committing to the wrong branch.
-
-
reflog-
Reverts a commit or branch that was deleted, by going back in time.
-
reflog .
-
-
git show \_COMMIT_ID (or) \_HEAD~\_number_of_commits_to_go_back-
Shows the given commit.
-
-
git status-
Gives information about commits and the staging area.
-
git status -s-
Gives the information in a shortened form; short format.
-
-
Logging
Navigate
-
Scroll:
-
Space→ next page -
b→ previous page -
Enter→ next line -
y→ previous line
-
-
Search:
-
/pattern→ search forward -
?pattern→ search backward -
n→ repeat search forward -
N→ repeat search backward
-
-
Go to start/end:
-
g→ start of file -
G→ end of file
-
-
Exit:
-
q→ quitlessand return to shell
-
Git Log
-
git log-
Ex:
-
git log --follow -p -m "--pretty=format:COMMIT: %ad HASH: %h" --word-diff -U0 --date=short -- "path.md"
-
-
Shows the change logs.
-
git log --oneline-
Shows the logs in a compact form.
-
-
Filter options can be by 'date', 'message', 'author', 'file' or 'branch'.
-
--follow-
Continue listing the history of a file beyond renames (works only for a single file).
-
-
--pretty-format-
%H-
commit hash
-
-
%h-
abbreviated commit hash
-
-
%T-
tree hash
-
-
%t-
abbreviated tree hash
-
-
%P-
parent hashes
-
-
%p-
abbreviated parent hashes
-
-
%an-
author name
-
-
%aN-
author name (respecting .mailmap, see git-shortlog or git-blame )
-
-
%ae-
author email
-
-
%aE-
author email (respecting .mailmap, see git-shortlog or git-blame )
-
-
%al-
author email local-part (the part before the
@sign)
-
-
%aL-
author local-part (see
%al) respecting .mailmap, see git-shortlog or git-blame )
-
-
%ad-
author date (format respects --date= option)
-
-
%aD-
author date, RFC2822 style
-
-
%ar-
author date, relative
-
-
%at-
author date, UNIX timestamp
-
-
%ai-
author date, ISO 8601-like format
-
-
%aI-
author date, strict ISO 8601 format
-
-
%as-
author date, short format (
YYYY-MM-DD)
-
-
%ah-
author date, human style (like the
--date=humanoption of git-rev-list )
-
-
%cn-
committer name
-
-
%cN-
committer name (respecting .mailmap, see git-shortlog or git-blame )
-
-
%ce-
committer email
-
-
%cE-
committer email (respecting .mailmap, see git-shortlog or git-blame )
-
-
%cl-
committer email local-part (the part before the
@sign)
-
-
%cL-
committer local-part (see
%cl) respecting .mailmap, see git-shortlog or git-blame )
-
-
%cd-
committer date (format respects --date= option)
-
-
%cD-
committer date, RFC2822 style
-
-
%cr-
committer date, relative
-
-
%ct-
committer date, UNIX timestamp
-
-
%ci-
committer date, ISO 8601-like format
-
-
%cI-
committer date, strict ISO 8601 format
-
-
%cs-
committer date, short format (
YYYY-MM-DD)
-
-
%ch-
committer date, human style (like the
--date=humanoption of git-rev-list )
-
-
%d-
ref names, like the --decorate option of git-log
-
-
%D-
ref names without the " (", ")" wrapping.
-
-
-
git blame-
For line-level attributions.
-
Submodules
-
Based on having a git repository inside another git repository.
-
The submodule files are in the local directory, but are not part of the main repository, therefore not part of the main repo's version control.
-
-
The video explains how to fetch submodules of an existing repository when cloning, since they are not downloaded automatically:
-
Run
git clone --recursive-submodules _repo_url_when cloning. -
Or run
git submodule update --init --recursiveafter cloning.
-
-
Etc
Conventions
Stuff
-
HEAD :
-
Current branch.
-
-
Trees :
-
Directories.
-
-
Blobs :
-
Files.
-
-
*.txt-
All files with .txt extension.
-
-
.-
All files.
-
Tag
-
In Git, a tag is a reference to a specific point in the repository’s history. Unlike branches, which can move as new commits are added, tags are static references to a specific commit. Tags are often used to mark important points in the repository’s history, such as releases (e.g., v1.0, v2.0).
-
Doesn't change anything about commits and branches.
-
Lightweight Tags :
-
Simple references to a commit and are essentially just a name for that commit.
-
They don’t store additional metadata such as the tagger’s name, email, or date.
-
Often used for temporary or quick references.
-
-
Annotated Tags :
-
Stored as full objects in the Git database and contain metadata.
-
Metadata includes the tagger’s name, email, date, and a tagging message.
-
Recommended for marking releases or other significant events because they provide more information.
-
-
Using an Annotated Tag, and writing a message 'message here':
-
Patch
-
Actually creates a "patch notes" of differences between commits.
-
Nothing is committed or changed; everything remains the same. It just saves a log file in the chosen location.
-
Example I made:
From c771e59a7b26cfd3670ccfb62e282c8e4a576e7b Mon Sep 17 00:00:00 2001
From: Caio Raphael <caioraphael00@gmail.com>
Date: Sat, 20 Jul 2024 08:47:29 -0300
Subject: [PATCH] f2
---
file_2.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 file_2.txt
diff --git a/file_2.txt b/file_2.txt
new file mode 100644
index 0000000..7ec9a4b
--- /dev/null
+++ b/file_2.txt
@@ -0,0 +1 @@
+aa
\ No newline at end of file
--
2.38.1.windows.1
-
Whatever. Weird reading.
-
The "save as patch" option when selecting commits does exactly the same. It doesn't change anything, it just downloads the .patch file.
Archive
-
Just downloads a branch into a .zip file.
-
Doesn't change anything in branches or commits.
-
In Git context, an "archive" typically refers to a packaged snapshot of the repository at a specific point in time. Useful for distribution, backup, or deployment. The
git archivecommand creates an archive file (e.g., .tar or .zip) of the repository’s contents.
Gitignore
Links
-
The '.gitignore' file from the 'Backup-dados' repo provides a very good example of using 'exceptions' in .gitignore. See it on GitHub or the local version in 'C:\Users\caior'.
How to stop tracking a directory/file that was previously an exception in .gitignore
-
If '.gitignore' is configured to ignore everything except a list of exceptions, and I want to start ignoring a file/folder (i.e., remove the exception) I do:
-
Modify the '.gitignore' file and submit only it to GitHub.
-
Remove the file/folder locally.
-
Commit the local changes and do a Fetch Origin and Push from GitHub Desktop to GitHub.
-
Done. After that, I can put the file/folder back in the local repo without problems, since it's no longer listed as an exception in '.gitignore'.
-
Security
Access Tokens
-
Explanation and example use of Access Tokens, and a bit about SSH Keys: video .
SSH Keys
-
A somewhat 'vague' explanation about SSH Keys, Public and Private: video .
Advanced Security
-
Video explaining several 'Advanced Security' concepts: GitHub channel video .
-
Secrets Scanning (scans Organization, Repository and Environment code for leaked secrets).
-
More detailed video: video .
-
-
CodeQL (Code Scanning) (scans code for security vulnerabilities).
-
Can be used to check for viruses or vulnerabilities in public repositories before making changes or forks.
-
Reminder: Query Language (QL) refers to any programming language that requests data and retrieves it from a database/systems using "queries".
-
-
Dependabot (checks dependencies against other open-source repositories).
-
Gitattributes
-
DON'T TOUCH THIS. EVER.
-
I CORRUPTED SOME FILES ONCE.
-
IF YOU DON'T KNOW HOW TO USE IT, DON'T USE IT.
-
FORBIDEN.
Providers
-
GitHub .
-
https://bitbucket.org/.
-
Seems like an alternative to GitHub, allowing private accounts with multiple people.
-
GitHub
Storage
-
In short:
-
Ideally keep below 1GB, but the maximum is 5GB; they send an email if you're close to that value.
-
There's a storage and bandwidth limit of 1GB for LFS (Large File Storage), used for very large files.
-
Account types
-
GitHub Free account:
-
Public:
-
(unsure).
-
Can do Automatic Merges of Pull Requests.
-
-
Private:
-
Doesn't have collaborator access restriction options; it's full-access (read-write) or nothing.
-
No Branch Protection options.
-
Can't do Automatic Merge of Pull Requests, but can be unlocked if you have paid accounts like 'GitHub Pro', 'GitHub Team' or 'GitHub Enterprise (Cloud or Server)'.
-
-
Owner and Collaborator access permissions: documentation .
-
-
Organization Free account:
-
Private:
-
Has limited collaborator access restrictions; read-only, write, admin, etc.
-
No Branch Protection options, but can be unlocked with paid plans like 'GitHub Pro', 'GitHub Team' or 'GitHub Enterprise'.
-
-
Public:
-
Has limited collaborator access restrictions; read-only, write, admin, etc.
-
Has all Branch Protection options.
-
-
Base permissions for Collaborators, Members, etc: documentation .
-
Read:
-
Cannot create new files on the remote.
-
Cannot edit any files or settings.
-
Can Pull (remote -> local) but cannot Push (local -> remote).
-
Can create Pull Requests, but cannot approve them because Write permission is required.
-
Cannot close or reopen others' Pull Requests.
-
-
Triage:
-
Main difference vs Read :
-
Still very limited, no Write permission, but can manage Issues and Pull Requests from others.
-
-
Cannot create new files on the remote.
-
Cannot edit files or settings.
-
Can Pull but cannot Push.
-
Can create Pull Requests but cannot approve them.
-
Can close and reopen other people's Pull Requests.
-
-
-
Solution for 'group privacy' with GitHub Free (Organization + Fork)
-
I moved the repository into an Organization I created.
-
Changed the Organization's default access restrictions to Read-Only.
-
Changed individual collaborator access for the repository to Read-Only.
-
Collaborator (Paola) forks the repository and edits that fork.
-
Results and implications:
-
High access restrictions for the collaborator on the original repository, since access is Read-only.
-
Changes can be made in the fork without security concerns; a Pull Request from the Fork to the Original is required to change the original.
-
Strangely, the owner of the Original repo can fully access and control the Fork, even without being a collaborator on that Fork.
-
See which private repositories I contribute to
-
{ viewer { repositories(first: 100, affiliations: [COLLABORATOR], privacy: PRIVATE) { nodes { name url owner { login } } } } }
GitClients
Terminal-based
LazyGit
Magit
-
Magit .
-
For Windows, Linux and Mac.
-
It's an Emacs plugin. Completely text-based, purely terminal.
Cong
-
Cong .
-
For Windows.
-
Couldn't find any videos about it.
-
Visual is kinda ~terminal/hacker, semi-terminal client.
-
Not friendly. No graph visualization.
-
When testing :
-
Opened but showed a gray screen.
-
From issues it seems to have many basic problematic things.
-
GitCola
-
GitCola .
-
For Windows, Linux and Mac.
-
Looks simplistic, somewhat terminal-oriented.
-
Couldn't find videos about it.
-
When testing :
-
UI looked very dated and visually terrible. Kinda bait.
-
(2025-05-27)
-
Very very bad.
-
-
GUIs
-
~ SourceGit .
-
For Windows, Linux and Mac.
-
Couldn't find videos about it.
-
Open Source.
-
*When testing:
-
Lots of features and very straightforward.
-
Didn't like the interface; unnecessarily dense.
-
It's an app I might keep in the background for occasional complex tasks.
-
Not my default app choice; complicated.
-
(2025-05-27)
-
Crashed, I had to pull the PC plug.
-
etc.
-
App is very unpleasant to use.
-
-
-
-
~ RelaGit .
-
Issue .
-
For Windows, Linux and Mac.
-
Couldn't find videos about it.
-
Open Source.
-
App is in beta.
-
Layout very similar to GitHubDesktop. Feels like an improved version, but didn't convince me due to install issues and smaller project trust.
-
*When testing:
-
No installer, just a folder with files.
-
(2024-06-15) Downloading and opening the app didn't work; it simply didn't open despite dependencies installed. There's an Issue about this.
-
(2024-06-15) Build attempt:
-
Need Node.js (v18+) and pnpm.
-
iwr https://get.pnpm.io/install.ps1 -useb | iex. -
Installed Node.js, didn't change defaults.
-
Restarted terminal.
-
git clone https://github.com/relagit/relagit relagit -
cd relagit -
pnpm i -
pnpm build(failed here).
-
-
-
-
-
For Windows, Linux and Mac.
-
Huge marketing; very annoying.
-
Beta.
-
Open Source.
-
Idea: "Virtual Branches".
-
"You don’t need to switch branches if you can work on several simultaneously. Fix your bug while you work on your feature.".
-
"Virtual branches are derived from the working directory, not the other way around..."
-
-
*When testing:
-
Felt buggy and clunky.
-
Old/new interface, incomplete.
-
-
-
-
*When testing:
-
Viewing commits of another branch switches you to that branch, which I HATE; causes file corruption and confusion if not careful.
-
That's why I uninstalled the app.
-
-
No decent way to handle merge conflicts.
-
-
-
-
For Windows, Linux and Mac.
-
Pretty cool. Liked the graph visualization.
-
Technically usable for free but with many limitations: Pricing .
-
7-day trial for full version.
-
Highly recommended as one of the best Git GUIs.
-
*When testing:
-
Interface felt idiotic with tutorials and unnecessary stuff, reminded me of VSCode.
-
After the 7-day trial, got message "The free plan does not support opening private or self-hosted repositories. Upgrade to open this repository", so I had to close the RPG Darkwood repo I had open.
-
-
-
-
For Windows, Linux and Mac.
-
No videos found.
-
Some features locked behind "premium": Pricing .
-
The colored dots likely represent 'New', 'Changed' and 'Removed'.
-
Site didn't impress me.
-
*When testing:
-
Has an 'AI Analysis' for commits, which I consider garbage.
-
Interface ugly and bland.
-
Not a fan.
-
30-day free trial then limited free version — inconsistent.
-
-
-
GitFiend.-
For Windows, Linux and Mac.
-
I couldn't find any video about it.
-
Seems to have been in beta for several years. Sounds stagnant in development.
-
*When testing:
-
I found the visual a bit washed out and not very pleasant to the eyes. Tab transitions are unnecessary and a bit laggy.
-
It auto-stages changes, which I like.
-
Has a design similar to GitHub Desktop, but with a history that has a light graph.
-
I didn't like it that much, but I didn't hate it either.
-
The app has zero customization and configuration.
-
There is no intuitive interface for performing merges. It's awkward and very ambiguous just like GitHub Desktop.
-
I didn't find any real advantage that would make me want to use this app over the generic/poor (but more reliable) GitHub Desktop.
-
-
-
GitAhead.-
For Windows.
-
No longer in active development.
-
Open Source.
-
*When testing:
-
I didn't like the UI at all. It reminds me of SourceTree's UI, being ultra dated / trying to be modern. It doesn't look good, it reminds me of Office stuff.
-
Simply didn't like the app.
-
-
-
-
For Windows and Mac.
-
It's from the company that made Bitbucket. ~Seems like it can sometimes show ads.
-
The interface is not very pretty. Feels a bit dated.
-
*When testing:
-
While trying to install, I immediately ran into a Bitbucket ad. Didn't like it.
-
The interface is very Office-like and ugly, cluttered. Not pleasant.
-
Didn't like it.
-
-
-
-
For Windows and Mac.
-
It's free for GitHub. For other platforms it is paid monthly. Some features are locked: Pricing .
-
Marketed as "Git for non-programmers".
-
*About:
-
It's officially an 'Asset manager' with git capabilities.
-
-
*When testing:
-
I found the interface a bit weird and odd. It tries to create a new 'workflow', but I found it more confusing than normal git.
-
It didn't feel plug-and-play. It's simply confusing and doesn't seem like 'git'. Pretty strange.
-
I tried downloading the app a second time. It's simply very bad, don't be fooled by the video about 'Anchor, GitHub and Godot'. The app is buggy, irresponsible, confusing. It's on free-trial.
-
It's a heavy and unnecessary app. Nothing simple. Nothing practical.
-
Don't use it.
-
-
-
Glint.-
For Windows, Linux and Mac.
-
"Upgrade to Premium for bonus features: Features ".
-
Couldn't find any video about it.
-
*When testing:
-
Didn't like the layout much. I felt it occupies more space than it should, showing too much information at once.
-
The main history view left me confused. Didn't like it.
-
Does not auto-stage changes.
-
The Discard Changes button is huge and next to the Stage option; that gives me a lot of discomfort.
-
Also, I dislike the locked features (aka tab limits).
-
-
-
Gitnuro.-
For Windows, Linux and Mac.
-
Couldn't find any video about it.
-
*When testing:
-
Found the layout unpleasant to the eyes and uninteresting. Reminded me of SourceTree's design; very boring.
-
Although the interface is minimalist, I found it confusing. Couldn't find the merge option.
-
Has an interface very similar to Glint, but Glint is better.
-
Does not auto-stage changes, which I find a bit annoying.
-
-
-
GittyUp.-
For Windows, Linux and Mac.
-
Couldn't find any video about it.
-
Open Source.
-
*When testing:
-
Found the interface quite ugly, dated and confusing.
-
Preferred to use GitHub Desktop.
-
-
-
-
For Windows.
-
Has a very old-looking visual.
-
-
GitForce.-
For Windows and Linux.
-
Ultra old, wow.
-
-
-
For Windows, Linux and Mac.
-
Can be evaluated for free, but inevitably you need to buy the license. The license only covers 3 years of updates.
-
-
Fork.-
For Windows and Mac.
-
Trial period, followed by a one-time purchase (for 1 person and 3 machines).
-
-
-
For Windows.
-
It's basically a terminal wrapper.
-
It's very ugly.
-
-
GitTower.-
For Windows and Mac.
-
30-day trial period, followed by an annual subscription.
-
-
SmartGit.-
For Windows, Linux and Mac.
-
It's free, but you need to buy a license for commercial use: app definition .
-
Found the app terribly ugly.
-