- Description:
- Table of Contents:
- Fork vs Clone:
- Git Basic Commands:
- Other Commands:
- Collaborations:
- References:
- Contact:
Introduction:
Github is an open-source code platform that allows us to collaborate with others developers through Git, the most popular decentralized VCS (Version Control System), *although, there are other VCS like Subversion for a more centralized approach.
This repository aims to be a complete guide of Git & 3°-party-tools that users should consider carrying on a daily basis, made by human-like systems completely in order to avoid misinformation and substantial errors. It pretends to be a reference for most git commands, illustrating some of the most used options & args. for basic/other commands meant to be used on a git terminal.
While not so user friendly, using terminals allows us to use more commands, to modify their syntax and to provide commands with many different
*options, arguments or objects, as well as to chain several commands successively or even make scripts written in git through unix-like systems.
The most popular ones are MAC OS and Linux, but Windows users can also use the Gitbash emulator provided by Git with its download.
- Fork: Merge with original repo is possible with a pull request.
- Clone: Merge with original repo is only achieved by pushing to fork and then a pull request.
Note: It is better to fork a repository before cloning it due to copyrights when the user is NOT declared as a contributor.
General steps:
- Fork repository.
- Clone forked repository.
- Make Changes in Local.
- Push to Personal Remote.
- Pull Request to Original Remote.
Note: It is a faster option to clone the original repository without a previous fork of the project if the user IS declared as a contributor.
General steps:
Refer to Github official documentation for more information related to contributions.
The following is a list of common git commands based on the Git Documentation.
Note: if you don't understand a term, check out the definitons section below.
Basic | Command | Description |
---|---|---|
1. help |
|
|
2. init |
|
|
3. clone |
|
|
4. config |
|
|
5. checkout |
|
|
6. fetch |
|
|
7.merge |
|
|
8. rebase |
|
|
9. pull |
|
|
10. add |
|
|
11. commit |
|
|
12.push |
|
|
13.pull request |
|
|
14. branch |
|
|
15. diff |
|
|
16. log |
|
|
17. revert |
|
|
18. reset |
|
|
19. stash |
|
|
20. status |
|
|
21. touch |
|
|
22. switch |
|
|
23. cd |
|
|
24. ls |
|
|
25. rm |
|
|
26. mv |
|
|
27. mkdir |
|
|
28. remote |
|
|
29. gitk |
|
|
Examples of third-party pkgs installation and usage is illustrated are illustrated by the following:
Basic | Command | Description |
---|---|---|
Installation with: pip/conda |
|
|
30. grip |
|
|
bash.script can be executed in pwd
to display githistory.xyz:
./githistory.sh <username> <repo> <branch> <file>
Note: Its usage is intended to view &/or extract changes by users in specific files with web scraping techniques & libraries.
See more here: BeautifulSoup, Scrapy for Python
or Puppeteer & Cheerio in JavaScript
.
- Origin: Primary working dir. of remote repositories by default.
- Fetch: Fetch is a safe pull version because local files aren't merged until they are reviewed, checked out & merged.
- Revert: Revert is safer than reset, checkout to discard (see 5.4 checkout), etc., because commit history isn't erased but an inverted commit is appended.
- Feature: Feature represents a branch of developments in progress with their descriptions.
- Rebase: Rebase is a rewritten branch from another but keep in mind it is not a good practice to rewrite public commits history (remote repositories).
Creating a backup branch is a good idea. This would allow us to perform a hard reset if the resulting rebase is unexpected. - Base: It is a commit id, branch, tag, or a relative reference to HEAD (e.g. HEAD~3).
Note: Branches should be called by their names even if they weren't specified (see 14. branch).
Tip: <main>
is the default name for remote repositories as <master>
is for local.
See Also:
Glossary
- git am ~ Splits patches from a mailbox into commit msg, author and patches to apply them to branch.
e.g:git am --keep-cr --signoff < a_file.patch
to apply patch as commit. - git apply ~ Apply a patch to files and add them to the index.
e.g:git apply < a_file.patch
to apply patch to files. - git archive ~ Combine multiple files in a single file but removes git data.
e.g:git archive --format=zip --output=archive.zip HEAD
to create a zip file with all files in HEAD. - git bisect ~ Binary search algorithm to find commit in project history which caused a bug.
e.g:git bisect start
to start the search. - git blame ~ Show what revision and author last modified each line of a file.
e.g:git blame <file>
to show the last author of each line in file. - git bugreport ~ Create a report to send to git mailing list.
e.g:git bugreport -o report.txt
to create a report and save it to report.txt. - git bundle ~ Move objects and refs by archive.
e.g:git bundle create <file> <branch>
to create a bundle with branch. - git cat-file ~ Provide content or type and size information for repository objects.
e.g:git cat-file -p <commit>
to show the content of commit. - git check-attr ~ Display git attributes.
e.g:git ls-files | xargs git check-attr myAttr
to show if an attribute is set for all the files in repo & overcome limit of 1024 files. - git check-mailmap ~ Show canonical names and email addresses of contacts.
e.g:git check-mailmap user1 <user1@domain.com>
to show the canonical name and email address of user1. - git check-ref-format ~ Ensure that a reference name is well formed.
e.g:git check-ref-format --branch @{-1}
print the name of the previous branch. - git check-ignore ~ Debug gitignore files.
e.g:git check-ignore -v <file>
to show the gitignore file that ignores file. - git cherry ~ Find commits not merged upstream.
e.g:git cherry -v <branch>
to show the commits not merged in branch. - git cherry-pick ~ Apply the changes introduced by some existing commits.
e.g:git cherry-pick <commit_id>
to apply the changes of commit to current branch. - git citool ~ Graphical alternative to git-commit.
e.g:git citool
to open the graphical commit tool. - git clean ~ Remove untracked files from the working tree.
e.g:git clean -i
to interactively remove untracked files. - git clone ~ Clone a repository into a new directory.
e.g:git clone <URL> <dir.>
to clone a repo with URL into directory. - git column ~ Display data in columns.
e.g:git column --mode=html <file>
to display file in html columns. - git commit ~ Record changes to the repository.
e.g:git commit -m <msg>
to commit with msg. - git commit-graph ~ Write and verify a commit-graph file.
e.g:git show-ref -s | git commit-graph write --stdin-commits
to write a commit-graph file for reachable commits. - git commit-tree ~ Create a new commit object.
e.g:git commit-tree <tree> -m <msg>
to create a commit with tree and msg. - git config ~ Get and set repository or global options.
e.g:git config --global user.name <name>
to set the global user name. - git count-objects ~ Count unpacked number of objects and their disk consumption.
e.g:git count-objects -v
to show the number of objects and their size. - git credential ~ Retrieve and store user credentials.
e.g:git credential fill
attempt to add "username" and "password" attributes by reading config credential helpers. - git credential-cache ~ Helper to temporarily store passwords in memory.
e.g:git config credential.helper cache
to set credentials automatic authentication & returns username/password blanks to fill. - git credential-store ~ Helper to store credentials on disk to reduce time to fill.
e.g:git config --global credential.helper store
to save credentials in plaintext PC disk, everyone in PC can read it (warning). - git cvsexportcommit ~ Export a single commit to a CVS checkout.
e.g:git cvsexportcommit <commit_id>
to export commit to a CVS directory. - git cvsimport ~ Create a new git repository from a CVS checkout.
e.g:git cvsimport -v -d <cvsroot> <module> <project>
to create a new git repository from a CVS checkout. - git cvsserver ~ Server for CVS clients to connect to and use Git repositories.
e.ggit cvsserver --base-path=<path> <repo>
to start the git cvsserver. - git daemon ~ A really simple server for Git repositories.
e.g:git daemon --reuseaddr --base-path=<dir.> --export-all
to restart server & look for repos in dir. to export. - git describe ~ Describe specific commits with their hash.
e.g:git describe <commit_id>
to describe commit (HEAD by default). - git diff ~ Show changes between commits, commit and working tree, etc.
e.g:git diff --stat
to show the summary of the changed files. - git diff-files ~ Show changes between index and working tree.
e.g:--diff-algorithm={minimal}
to include the smallest possible diff are included. - git diff-index ~ Compare a tree to the working tree or index.
e.g:git diff-index --compact-summary HEAD
to show the summary of the changed files in HEAD. - git diff-tree ~ Compares the content and mode of the blobs found via two tree objects.
e.g:git diff-tree --s7hortstat HEAD
to show the summary of the changed files in HEAD. - git difftool ~ Show changes using common diff tools.
e.g:git difftool --tool-help
to show the list of available tools. - git fast-export ~ Dumps the given revisions in a form suitable to be piped with fast-import.
e.g:git fast-export --all
to export all data. - git fast-import ~ Reads data stream from std. input and writes it into one or more packfiles.
e.g:git fast-import --max-pack-size=1G
to import data into a packfile of size 1G (default is unlimited) - git fetch ~ Download objects and refs from another repository.
e.g:git fetch --dry-run
to show output without making any changes. - git fetch-pack ~ Receive missing objects from another repository.
e.g:git fetch-pack --prune --all
to fetch all objects and prune refs that are missing on the remote. - git filter-branch ~ Rewrite branches.
e.g:git filter-branch --tree-filter 'rm -f *.txt' HEAD
to remove all .txt files. - git filter-repo ~ Quickly rewrite Git repository history.
\ e.g:git filter-repo --invert-paths --path 'README.md'
to remove all files except README.md. - git fmt-merge-msg ~ Produce a merge commit message.
e.g:git fmt-merge-msg -m
Use msg instead of branch names for the first line of the log message. - git for-each-ref ~ Iterate over references.
e.g:git for-each-ref --format='%(refname)' refs/heads
to list all branches. - git format-patch ~ Prepare patches for e-mail submission.
e.g:git format-patch -root <commit>
to format everything up from start until commit. - git fsck ~ Verifies the connectivity and validity of the objects in the database.
e.g:git fsck --cache
to check the connectivity and validity of the objects in the cache. - git gc ~ Cleanup unnecessary files and optimize the local repository.
e.g:git gc --force
to force garbage collection. - git get-tar-commit-id ~ Extract commit ID from an archive created using git-archive.
e.g:git get-tar-commit-id <file>
to extract most recent commit ID from file. - git grep ~ Print lines matching a pattern.
e.g:git grep -n 'print' <file>
to print lines containing 'print' and their line numbers. - git gui ~ A portable graphical interface to Git.
e.g:git gui citool --nocommit
Checks for unmerged entries on index and exits gui without committing. - git hash-object ~ Compute object ID and optionally creates a blob from a file.
e.g:git hash-object -w --path <file>
to write the blob to the object database and print its hash. - git help ~ Display help information about Git.
e.g:git help -all
to display all git commands. - git http-fetch ~ Download objects and refs from another repository via HTTP.
e.g:git http-fetch -v <[URL]/refs>
to report all refs downloaded in repo with URL. - git http-backend ~ Server side implementation of Git over HTTP.
e.g:git http-backend --help
to display help for http-backend. - git imap-send ~ Send a collection of patches from stdin to an IMAP folder.
e.g:git imap-send git format-patch --cover-letter -M --stdout origin/master | git imap-send
to send patches from origin/master to IMAP folder once the commits are ready to send. - git index-pack ~ Build pack index file for an existing packed archive.
e.g:git index-pack --max-input-size=1G
to build pack index file and die if the pack is larger than 1G (or any). - git init ~ Create an empty Git repository or reinitialize an existing one.
e.g:git init -b <branch-name>
to create an empty local Git repository with given branch name. - git init-db ~ Create an empty Git repository or reinitialize an existing one.
e.g:git init-db --config <config-file>
to create an empty local Git repository with given config file. - git instaweb ~ Instantly browse your working repository in gitweb.
e.g:git instaweb --httpd=python --port=8080
to start a python web server on port 8080. - git interpret-trailers ~ Parse trailer lines from text.
e.g:git interpret-trailers --check <file>
to check if file contains trailer lines (similar to RFC 822 e-mail headers) - git log ~ Show commit logs.
e.g:git log --oneline --decorate --graph --all
to display all commits in a nice format. - git ls-files ~ Show information about files in the index and the working tree.
e.g:git ls-files -u
to show unmerged files. - git ls-remote ~ List references in a remote repository.
e.g:git ls-remote <[URL]/refs>
to display references in a remote repository URL associated with commits IDs. - git ls-tree ~ List the contents of a tree object.
e.g:git ls-tree -d <tree>
to list the named tree only, without its children. - git mailinfo ~ Extracts patch and authorship from a single e-mail message.
e.g:git mailinfo -k <msg> <patch>
Removes unnecessary headers from msg and writes the result to patch. - git mailsplit ~ Splits a single mailbox into a list of files.
e.g:git mailsplit -o<directory> <mbox>
to split given mbox file in directory as individual msg files. - git merge ~ Join two or more development histories together.
e.g:git merge --allow-unrelated-histories <branch>
override the check for unrelated histories with common ancestors and merge. - git merge-base ~ Find as good common ancestors as possible for a merge.
e.g:git merge-base --is-ancestor <commit_id> <commit_id>
to check if first commit_id is an ancestor of the second and return 0 if true and 1 if not.* - git merge-file ~ Run a three-way file merge.
e.g:git merge-file <current_file> <base_file> <other_file>
incorporate changes from other_file into current_file, using base_file as common base - git merge-index ~ Run a merge for files in the index.
e.g:git merge-index -o -a <file>
to run a merge for all files in index that need it & write result to file. - git merge-tree ~ Show three-way merge without touching index.
e.g:git merge-tree <base-tree> <branch1> <branch2>
Reads the trees & outputs the result of merge without storing results in index.* - git mergetool ~ Run merge conflict resolution tools to resolve merge conflicts.
e.g:git mergetool --tool-help
to list available tools. - merge-index ~ Run a merge for files in the index.
e.g:git merge-index -o <file>
to run a merge for files in the index that need merging and write the result to file. - git mktag ~ Create a tag object.
e.g:git mktag <mytag>
*to create a tag object with given tag name and die if the connection to the object store fails. - git mktree ~ Build a tree-object from ls-tree formatted text.
e.g:git mktree --batch <file>
to create more than one tree object from a file. - git mv ~ Move or rename a file, a directory, or a symlink.
e.g:git mv -v <source> <destination>
to move source to destination and display the result of the move. - git name-rev ~ Find symbolic names for given revs.
e.g:git log | git name-rev --annotate-stdin
to retrieve author, date and commit hash from the logs. - git notes ~ Add or inspect object notes.
e.g:git notes add -m <msg> <commit>
to add a note/msg to commit. - git pack-objects ~ Create a packed set of objects from one or more packed archives compressed
. e.g:git pack-object --all-progress-implied
to create a packed set of objects from one or more packed archives compressed. - git pack-redundant ~ Find redundant pack files for piping to xargs rm.
e.g:git pack-redundant --all --i-still-use-this
to find all redundant pack files in repo (nominated for removal). - git pack-refs ~ Pack heads and tags for efficient repository access.
e.g:git pack-refs --all
to pack heads and tags that are already packed - git patch-id ~ Compute unique ID for a patch.
e.g:git patch-id <file>
to compute unique ID for a patch. - git prune ~ Prune all unreachable objects from the object database.
e.g:git prune --expire <time>
to prune all unreachable objects from the object database that are older than time. - git prune-packed ~ Prune loose objects that are already in pack files.
e.g:git prune-packed -n
to prune loose objects that are already in pack files and display what would be done. - git pull ~ Fetch from and integrate with another repository or a local branch.
e.g:git pull <remote> <local>
to fetch from and integrate with local branch. - git push ~ Update remote refs along with associated objects.
e.g:git push
to update remote refs along with associated objects. - git range-diff ~ Show changes between two commit ranges.
e.g:git range-diff <commit_1> <commit_2>
to show changes between two commit ranges - git read-tree ~ Reads tree information into the index.
e.g:git read-tree -m <tree-ish1> <tree-ish2> <tree/ish3>
to read tree information into the index and merge the trees. - git rebase ~ Reapply commits on top of another base tip.
e.g:git rebase -i <base> <branch>
to rebase interactively a branch on base. - git receive-pack ~ Receive what is pushed into the repository.
Note: This command is not meant to be invoked directly. - git reflog ~ Manage reflog information.
e.g:git reflog show
to show the reflog for the current branch like log. - git remote ~ Manage set of tracked repositories.
e.g:git remote add <remote> <URL>
to add a remote named remote with URL. - git remote-ext ~ External helper to communicate with a remote, used by default with clone, push, remote add & where.
Note: This command is not used normally by end users but it is instead invoked when interacting with remote repos. - git remote-fd ~ Helper to communicate with a remote repository when calling git fetch, push or archive.
Note: This command is not invoked by end users but scripts calling commands to setup a bidirectional socket with remotes. - git repack ~ Pack unpacked objects in a repository or for pack reorganization.
e.g:git repack -a -d -f --depth=250 --window=250
Single pack repo by removing reduntant packs & reusing existing deltas. Set up 250mb depth and window (default=10,50). - git replace ~ Create, list, delete refs to replace objects.
e.g:git replace --graft <commit_id> <new-parent>
to create a new commit with commit content but by replacing its parent with new-parent. - git request-pull ~ Request upstream to pull changes into their tree.
e.g:git request-pull <upstream_commit-id> <URL>
to make a pull-request starting from commit to repo URL to be pulled from. - git rerere ~ Reuse recorded resolution of conflicting merges.
e.g:git rerere diff
to show the recorded state of resolution, what you've started with and what you've ended up with. - git reset ~ Reset current HEAD to the specified state.
e.g:git reset --soft HEAD~n
*to make a hard reset n commits back but able to recover changes with git commit. - git rev-list ~ Lists commits by building commit ancestry graphs.
e.g:
git rev-list <commit_id > ^ HEAD --count
to count the number of commits between commit_id and HEAD. - git rev-parse ~ Ancillary plumbing command for parameters.
e.g:git rev-parse --short HEAD
to get the short version hash of HEAD. - git revert ~ Revert some existing commits.
e.g:git revert HEAD~n
to revert the last n commits. - git rm ~ Remove files from the working tree and from the index.
e.g:git rm <file>
to remove file from remote and local. - git send-email ~ Send a collection of patches as emails.
e.g:git send-email --from=<sender> --to=<recipient> --compose
to send email from sender adress to recipient by invoking a text editor. - git shortlog ~ Summarize 'git log' output.
e.g:git shortlog -s -n
to show the number of commits per author. - git show ~ Show various types of objects.
e.g:git show --expand-tabs=n
to show repository with tabs expanded to n. - git show-branch ~ Show branches and their commits.
e.g:git show-branch--all
to show all branches and their commits. - git stage ~ Stage file contents for the next commit.
e.g:git stage--clear
to clear the staging area. - git stash ~ Stash the changes in a dirty working directory away.
e.g:git stash--keep-index
to stash the changes in a dirty working directory away but keep the index. - git status ~ Show the working tree status.
e.g:git status--short
to show the working tree status in short format. - git stripspace ~ Remove unnecessary whitespace.
e.g:git stripspace--comment-lines
to remove unnecessary whitespace from comment lines. - git submodule ~ Initialize, update or inspect submodules.
e.g:git submodule--depth=1
to initialize, update or inspect submodules with depth 1. - git tag ~ Create, list, delete or verify a tag object signed with GPG.
e.g:git tag --annotate
to create, list, delete or verify a tag object signed with GPG. - git unpack-file ~ Unpack a packed archive.
e.g:git unpack-file --list
to list the contents of a packed archive. - git unpack-objects ~ Unpack objects from a packed archive.
e.g:git unpack-objects --all
to unpack all objects from a packed archive. - git update-index ~ Register file contents in the working tree to the index.
e.g:git update-index--refresh
to register file contents in the working tree to the index. - git update-ref ~ Update the object name stored in a ref safely.
e.g:git update-ref--no-deref
to update the object name stored in a ref safely. - git update-server-info ~ Update auxiliary info file to help dumb servers.
e.g:git update-server-info--force
to update the file even if it is not necessary. - git upload-archive ~ Send archive back to git-upload-archive on the other end.
e.g:git upload-archive
to send archive back to git-upload-archive on the other end. - git upload-pack ~ Send objects packed back to git-upload-pack on the other end.
e.g:git upload-pack
to send objects packed back to git-upload-pack on the other end. - git var ~ Show a Git logical variable.
e.g:git var -l
to show a Git logical variable. - git verify-commit ~ Check the GPG signature of commits.
e.g:git verify-commit <commit>
to check the GPG signature of commits. - git verify-pack ~ Check the GPG signature of packed objects.
e.g:git verify-pack
to check the GPG signature of packed objects. - git verify-tag ~ Check the GPG signature of tags.
e.g:git verify-tag <tag>
to check the GPG signature of tags. - git web--browse ~ Show a file or directory from web browser.
e.g:git web--browse <URL>
to show a file or directory from a web browser. - git whatchanged ~ Show logs with difference each commit introduces.
e.g:git whatchanged --stat
to show logs with difference each commit introduces. - git write-tree ~ Create a tree object from the current index.
e.g:git write-tree --missing-ok
to create a tree object from the current index.
- Git
- Linux Man
- Ubuntu Manuals
- Official Git Pro ebook
Collaborations:
For quick changes proposed via web you can follow these steps:
- Fork repo.
- Open
vscode.dev
and selectOpen Repository
- Paste the forked repo
URL
or select it manually. - Make changes, stage, commit and create a pull request.
Or you can use the Codespaces
feature: