Skip to content

petrkle/hacktoberfest

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ™Œ Hacktoberfest

All Contributors

This is a #Hacktoberfest training git repo on GitHub. It contains resources for learning Git. 99% of the contributions in this repository are from different first time beginners just like you. So, jump right in! 🎯

Meetup Event sponsorship DigitalOcean β†’

DO

πŸ’™ Git Resources:

Listing a few git resources here for everyone.

⚑️ Git Basics:

⚑️ Git Tutorials:

There are tons of learning material on the Web

⚑️ Git for WordPress:

⚑️ Git Tools:

Various tools for daily operations

  • GitHub Desktop β€” Git Client by GitHub. works with GitHub and GitHub Enterprise seamless
  • SourceTree β€” free (in-beer) GUI client. Windows and Mac only
  • GitKraken β€” a cross Git client for Windows, Mac & Linux. Electron based. Free for non-commercial use and paid Pro version is available.
  • Tower β€” a popular non-free Git GUI client. Mac and Windows
  • SmartGit β€” a commercial comprehensive SCM client with Git, SVN, Mercurial. cross-platform (works on Windows, Mac and Linux)
  • RabbitVCS β€” TortoiseSVN inspired graphic tool for version control systems, with Nautilus and Thunar integration
  • gitg β€” a open-source GTK+ GUI client
  • git-cola β€” a cross-platform Git GUI client
  • SGit β€” Git client for Android 4.x
  • Ungit β€” The easiest way to use git. On any platform. Anywhere.
  • MyRepos β€” a tool to manage multiple version control repositories
  • awesome-git-addons β€” lists more than 20 git addons including all available commands
  • GitIgnore Collection β€” collection of gitignore files for various programming language
  • git-extras – git utilities adding useful git commands
  • git-extra-commands β€” Another collection of useful git commands
  • GitKraken β€” a cross Git client for Windows, Mac & Linux. Electron based. Free for non-commercial use and paid Pro version is available.
  • GitUp β€” a clean, minimal Git client. Mac only.
  • GitExtensions β€” a shell extension, a Visual Studio 2010-2015 plugin and a standalone Git repository tool.

⚑️ Git Extensions

Git is designed for source control management. Extensions help people to extend the idea and push version control to everywhere

  • Git Large File Storage β€” practical solution for versioning large files. supported by GitHub
  • Git Virtual File System or GVFS β€” solution for managing very large Git repository while maintaining speed and efficiency of most operations, in development by Microsoft.
  • git-annex β€” allow managing massive binaries among machines, as if operating a standard git repository. Possible to create a synchronized folder with git-annex assistant

⚑️ Git Repository Hosting

People have plenty of options to host their source code

  • GitHub β€” the de-facto git hosting service. Perfect integration with most external services.
  • GitLab.com β€” a free Git repository hosting service served by GitLab EE. Unlimited repositories and private collaborators
  • BitBucket β€” well-known for its free private repository (5 user max).
  • Kiln β€” paid Git repository hosting service
  • CodePlex β€” Microsoft’s free open source code hosting service with many ASP/C# OSS projects
  • AWS CodeCommit β€” a SaaS service provided by Amazon Web Service on high availability infrastructure
  • Codeplane β€” a paid Git repository hosting service with no contributor limit
  • Deveo β€” a paid repository hosting service with support for Git, Subversion, Mercurial, WebDAV

⚑️ Git Self-Hosted Repository

Or you can host the code yourselves

  • Gitolite β€” a simple with fine-grained access control
  • GitHub Enterprise β€” self-hosted solution provided from GitHub
  • Bitbucket Server β€” self-hosted refrom Atlassian. Good integration with JIRA and other Atlassian products
  • GitLab CE/EE β€” a popular open-source Git (CE) with paid support option (EE).
  • Upsource β€” recent offer from Jetbrains, a famos developer-oriented software company. Code repository hosting feature pending. Free for 10 users. Good integration with YouTrack and TeamCity
  • GitBucket β€” a GitHub clone powered by Scala.
  • Gogs β€” a self-hosted Git Service written in Go.
  • GitBlit β€” Pure Java Stack for managing, view, and serving Git repositories.
  • Apache Allura β€” an open source implementation of project hosting platform
  • Phabricator β€” an integrated set of powerful tools to help companies build higher quality software
  • RhodeCode CE/EE β€” a platform delivering enterprise source code management

⚑️ Git Workflow

Inexpensive branching allows people adopt workflows other than the classic centralilzed workflow

⚑️ Git Hook management

Git provide hooks at commit/push phrase, allowing integration with and code quality checking tool and Continuous Integration (CI)

  • pre-commit β€” a framework for managing and maintaining multi-language pre-commit hooks from Yelp. Extensive support for multiple programming language.
  • Overcommit β€” a extendable Git hook manager written with Ruby.
  • git-hooks β€” tool to manage project, user, and global Git hooks
  • quickhook β€” a fast, Unix'y, opinionated Git hook runner

⚑️ GitHub Resources

A curated list of GitHub's Resources.

The awesomeness is currently organized into just a few different buckets:


Infomation for People Who Are New to GitHub

  • Code School's Try Git β€” If you'd like to better understand Git, one of the technologys that makes GitHub possible, this is a great place to start. No GitHub account required.
  • Git-it -- πŸ’» πŸŽ“ A workshopper for learning Git and GitHub.
  • On-Demand GitHub Training β€” Self-paced, interactive projects created and maintained by GitHub's own Training team.
  • Bingo Board -- Play bingo πŸ’₯ by sending pull requests!
  • Writing on GitHub β€” GitHub's own guide to using GitHub for more than just software development.
  • GitHubGuides β€” GitHub Training & Guides on YouTube.
  • GitHub Pages β€” Websites for you and your projects. Hosted directly from your GitHub repository. Just edit, push, and your changes are live.
  • Filetypes that GitHub can do magic with:
    • GeoJSON/TopoJSON β€” Instantly render maps when you add a GeoJSON file to a repository.
    • iPython/Jupyter β€” Yes, that's right, GitHub also renders ipynb files right in the browser. The possibilities are endless.
    • PDF β€” View PDFs right in your browser.
    • STL files β€” It's pretty amazing, 3D right in the browser.
    • CSV β€” Data journalists and civic data nerds rejoice, comma separated values right in the browser!
    • SVG β€” Not only can you view scalable vector graphics in the browser, but you can see the difference between versions visually! You've got to see it to believe it. (In fact, you can do this with most image files.)
    • PSD β€” That's right, same idea as SVG, but for Photoshop files!
  • GitHub Government Community β€” Information on joining GitHub's government community β€” a collaborative community for sharing best practices in furtherance of open source, open data, and open government efforts.
  • Classroom for GitHub β€” Your course assignments on GitHub.

Resources for Those Already Familiar With GitHub

  • GitHub Cheat Sheet β€” Use this list to test your GitHub knowledge.
  • GitHub Universe β€” Two full days on how to build, collaborate, and deploy great software, presented by GitHub. October 1 & 2, 2015, SF.
  • GitHub Desktop β€” Simple collaboration from your desktop.
  • Atom β€” Did you know that GitHub makes an editor? Use it to write, code, and more.
  • Electron β€” Build cross platform desktop apps with web technologies
  • GitHub Buttons β€” Showcase your GitHub repo's success with hotlinkable GitHub star, fork, or follow buttons.
  • Resume β€” Resumes generated using GitHub.
  • Speaker Deck β€” Share Presentations without the Mess, by GitHub.
  • Blocks β€” This is a simple viewer for code examples hosted on GitHub Gist. (Introduction is here)
  • Block Builder β€” Quickly create, edit, and fork D3.js examples
  • GitHub Template Guidelines β€” Guidelines for creating template files for a GitHub project..

Tips, Tricks, Tools, and Add-Ons for GitHub Power Users

  • GitHub Integrations Directory β€” Use your favorite tools with GitHub.
  • GitHub Cheat Sheet β€” Use this list to test your GitHub knowledge. (A resource so good, it's worth mentioning twice.)
  • A collection of awesome browser extensions for GitHub. β€” Well, the link kinda' says it all.
  • Gitter β€” Chat, for GitHub. Unlimited public rooms and one-to-one chats, free.
  • Zenhub β€” Project management inside of GitHub, including kanban boards and more.
  • HuBoard β€” Instant project management for your GitHub issues (sadly, no free plan, but appears to be open source)
  • Overv.io β€” Agile project management for teams who love GitHub. Kanban baords and more.
  • Penflip β€” Collaborative writing and version control, powered by GitLab (similar to GitHub).
  • Gitbook β€” A modern publishing toolchain. Simply taking you from ideas to finished, polished books.
  • Prose β€” Prose provides a beautifully simple content authoring environment for CMS-free websites. It's a web-based interface for managing content on GitHub.
  • Redliner β€” A tool for facilitating the redlining of documents with the GitHub uninitiated.
  • Gatekeeper β€” Enables client-side applications to dance OAuth with GitHub.
  • github-secret-keeper β€” Microservice to enable GitHub login for multiple server-less applications.
  • Hub β€” A command line tool that wraps git in order to extend it with extra features and commands that make working with GitHub easier.
  • Ghizmo β€” A command line for GitHub, allowing access to all APIs.
  • cli-github β€” Github made pretty, within the command line.
  • GitHub Dark β€” A sophisticated dark theme for GitHub.
  • github-issues-import β€” A Python script that allows you to import issues and pull requests from one GitHub repository to another
  • Github-Auto-Issue-Creator β€” A Python script that searches a GitHub repository (locally) and automatically creates GitHub issues for TODO statements, keeping them tracked.
  • Problem Child β€” Allows authenticated or anonymous users to fill out a standard web form to create GitHub issues (and pull requests).
  • gitify β€” All your GitHub notifications on your menu.
  • HubPress β€” A web application to build your Blog on GitHub
  • TinyPress β€” TinyPress is the easiest way to publish a blog on GitHub.
  • Issue and Pull Request Template Generator β€” Generate templates customized to your project, with the help of Cthulhu and Lewis Carroll
  • Noteit β€” Manage your notes at CLI with GitHub Gists.
  • Zappr β€” A free/open-source GitHub integration that removes bottlenecks around pull request approval and helps dev teams to painlessly abide by compliance requirements.
  • Migrating to Git LFS β€” Easily manage huge files in your Git projects, useful for Data Science projects

Novel Uses of GitHub

⚑️ Git Cheat Sheet


Setup

Show current configuration:
$ git config --list
Show repository configuration:
$ git config --local --list
Show global configuration:
$ git config --global --list
Show system configuration:
$ git config --system --list
Set a name that is identifiable for credit when review version history:
$ git config --global user.name β€œ[firstname lastname]”
Set an email address that will be associated with each history marker:
$ git config --global user.email β€œ[valid-email]”
Set automatic command line coloring for Git for easy reviewing:
$ git config --global color.ui auto
Set global editor for commit:
$ git config --global core.editor vi

Configuration Files

Repository specific configuration file [--local]:
<repo>/.git/config
User-specific configuration file [--global]:
~/.gitconfig
System-wide configuration file [--system]:
/etc/gitconfig

Create

Clone an existing repository:

There are two ways:

Via SSH

$ git clone ssh://user@domain.com/repo.git

Via HTTP

$ git clone http://domain.com/user/repo.git
Create a new local repository:
$ git init

Local Changes

Changes in working directory:
$ git status
Changes to tracked files:
$ git diff
Add all current changes to the next commit:
$ git add .
Add some changes in <file> to the next commit:
$ git add -p <file>
Commit all local changes in tracked files:
$ git commit -a
Commit previously staged changes:
$ git commit
Commit with message:
$ git commit -m 'message here'
Commit skipping the staging area and adding message:
$ git commit -am 'message here'
Commit to some previous date:
$ git commit --date="`date --date='n day ago'`" -am "<Commit Message Here>"
Change last commit:

Don't amend published commits!

$ git commit -a --amend
Amend with last commit but use the previous commit log message

Don't amend published commits!

$ git commit --amend --no-edit
Change committer date of last commit:
GIT_COMMITTER_DATE="date" git commit --amend
Change Author date of last commit:
$ git commit --amend --date="date"
Move uncommitted changes from current branch to some other branch:
$ git stash
$ git checkout branch2
$ git stash pop
Restore stashed changes back to current branch:
$ git stash apply

Restore particular stash back to current branch:

  • {stash_number} can be obtained from git stash list
$ git stash apply stash@{stash_number}
Remove the last set of stashed changes:
$ git stash drop

Search

A text search on all files in the directory:
$ git grep "Hello"
In any version of a text search:
$ git grep "Hello" v2.5

Commit History

Show all commits, starting with newest (it'll show the hash, author information, date of commit and title of the commit):
$ git log
Show all the commits(it'll show just the commit hash and the commit message):
$ git log --oneline
Show all commits of a specific user:
$ git log --author="username"
Show changes over time for a specific file:
$ git log -p <file>
Display commits that are present only in remote/branch in right side
$ git log --oneline <origin/master>..<remote/master> --left-right
Who changed, what and when in <file>:
$ git blame <file>
Show Reference log:
$ git reflog show
Delete Reference log:
$ git reflog delete

Branches & Tags

List all local branches:
$ git branch

List local/remote branches

$ git branch -a
List all remote branches:
$ git branch -r
Switch HEAD branch:
$ git checkout <branch>
Checkout single file from different branch
$ git checkout <branch> -- <filename>
Create and switch new branch:
$ git checkout -b <branch>

Checkout and create a new branch from existing commit

$ git checkout <commit-hash> -b <new_branch_name>
Create a new branch based on your current HEAD:
$ git branch <new-branch>
Create a new tracking branch based on a remote branch:
$ git branch --track <new-branch> <remote-branch>
Delete a local branch:
$ git branch -d <branch>
Rename current branch to new branch name
$ git branch -m <new_branch_name>
Force delete a local branch:

You will lose unmerged changes!

$ git branch -D <branch>
Mark the current commit with a tag:
$ git tag <tag-name>
Mark the current commit with a tag that includes a message:
$ git tag -a <tag-name>

Update & Publish

List all current configured remotes:
$ git remote -v
Show information about a remote:
$ git remote show <remote>
Add new remote repository, named <remote>:
$ git remote add <remote> <url>
Download all changes from <remote>, but don't integrate into HEAD:
$ git fetch <remote>
Download changes and directly merge/integrate into HEAD:
$ git remote pull <remote> <url>
Get all changes from HEAD to local repository:
$ git pull origin master
Get all changes from HEAD to local repository without a merge:
$ git pull --rebase <remote> <branch>
Publish local changes on a remote:
$ git push remote <remote> <branch>
Delete a branch on the remote:
$ git push <remote> :<branch> (since Git v1.5.0)

OR

$ git push <remote> --delete <branch> (since Git v1.7.0)
Publish your tags:
$ git push --tags

Configure the merge tool globally to meld (editor)

$ git config --global merge.tool meld
Use your configured merge tool to solve conflicts:
$ git mergetool

Merge & Rebase

Merge branch into your current HEAD:
$ git merge <branch>
Rebase your current HEAD onto <branch>:

Don't rebase published commit!

$ git rebase <branch>
Abort a rebase:
$ git rebase --abort
Continue a rebase after resolving conflicts:
$ git rebase --continue
Use your editor to manually solve conflicts and (after resolving) mark file as resolved:
$ git add <resolved-file>
$ git rm <resolved-file>
Squashing commits:
$ git rebase -i <commit-just-before-first>

Now replace this,

pick <commit_id>
pick <commit_id2>
pick <commit_id3>

to this,

pick <commit_id>
squash <commit_id2>
squash <commit_id3>

Undo

Discard all local changes in your working directory:
$ git reset --hard HEAD
Get all the files out of the staging area(i.e. undo the last git add):
$ git reset HEAD
Discard local changes in a specific file:
$ git checkout HEAD <file>
Revert a commit (by producing a new commit with contrary changes):
$ git revert <commit>
Reset your HEAD pointer to a previous commit and discard all changes since then:
$ git reset --hard <commit>
Reset your HEAD pointer to a remote branch current state.
$ git reset --hard <remote/branch> e.g., upstream/master, origin/my-feature
Reset your HEAD pointer to a previous commit and preserve all changes as unstaged changes:
$ git reset <commit>
Reset your HEAD pointer to a previous commit and preserve uncommitted local changes:
$ git reset --keep <commit>
Remove files that were accidentally committed before they were added to .gitignore
$ git rm -r --cached .
$ git add .
$ git commit -m "remove xyz file"

⚑️ Git-Flow

Improved Git-flow


Setup

You need a working git installation as prerequisite. Git flow works on OSX, Linux and Windows.
OSX Homebrew:
$ brew install git-flow-avh
OSX Macports:
$ port install git-flow
Linux (Debian-based):
$ sudo apt-get install git-flow
Windows (Cygwin):
You need wget and util-linux to install git-flow.
$ wget -q -O - --no-check-certificate https://raw.githubusercontent.com/petervanderdoes/gitflow/develop/contrib/gitflow-installer.sh install <state> | bash

Getting Started

Git flow needs to be initialized in order to customize your project setup. Start using git-flow by initializing it inside an existing git repository:
Initialize:
You'll have to answer a few questions regarding the naming conventions for your branches. It's recommended to use the default values.
git flow init

OR

To use default
git flow init -d

Features

Develop new features for upcoming releases. Typically exist in developers repos only.
Start a new feature:
This action creates a new feature branch based on 'develop' and switches to it.
git flow feature start MYFEATURE
Finish up a feature:
Finish the development of a feature. This action performs the following:
1) Merged MYFEATURE into 'develop'.
2) Removes the feature branch.
3) Switches back to 'develop' branch
git flow feature finish MYFEATURE
Publish a feature:
Are you developing a feature in collaboration? Publish a feature to the remote server so it can be used by other users.
git flow feature publish MYFEATURE
Getting a published feature:
Get a feature published by another user.
git flow feature pull origin MYFEATURE
Tracking a origin feature:
You can track a feature on origin by using
git flow feature track MYFEATURE

Make a Release

Support preparation of a new production release. Allow for minor bug fixes and preparing meta-data for a release
Start a release:
To start a release, use the git flow release command. It creates a release branch created from the 'develop' branch. You can optionally supply a [BASE] commit sha-1 hash to start the release from. The commit must be on the 'develop' branch.
git flow release start RELEASE [BASE]
It's wise to publish the release branch after creating it to allow release commits by other developers. Do it similar to feature publishing with the command:
git flow release publish RELEASE
(You can track a remote release with the: git flow release track RELEASE command)
Finish up a release:
Finishing a release is one of the big steps in git branching. It performs several actions:
1) Merges the release branch back into 'master'
2) Tags the release with its name
3) Back-merges the release into 'develop'
4) Removes the release branch
git flow release finish RELEASE
Don't forget to push your tags with git push --tags

Hotfixes

Hotfixes arise from the necessity to act immediately upon an undesired state of a live production version. May be branched off from the corresponding tag on the master branch that marks the production version.
Git flow hotfix start:
Like the other git flow commands, a hotfix is started with
$ git flow hotfix start VERSION [BASENAME]
The version argument hereby marks the new hotfix release name. Optionally you can specify a basename to start from.
Finish a hotfix:
By finishing a hotfix it gets merged back into develop and master. Additionally the master merge is tagged with the hotfix version
git flow hotfix finish VERSION

Commands

Git


Git flow schema

Git


⚑️ Git Tips

Collection of git-tips, want to add your tips? Checkout contributing.md

Tools:

P.S: All these commands are tested on git version 2.7.4 (Apple Git-66).

Everyday Git in twenty commands or so

git help everyday

Show helpful guides that come with Git

git help -g

Search change by content

git log -S'<a term in the source>'

Sync with remote, overwrite local changes

git fetch origin && git reset --hard origin/master && git clean -f -d

List of all files till a commit

git ls-tree --name-only -r <commit-ish>

Git reset first commit

git update-ref -d HEAD

List all the conflicted files

git diff --name-only --diff-filter=U

List of all files changed in a commit

git diff-tree --no-commit-id --name-only -r <commit-ish>

Unstaged changes since last commit

git diff

Changes staged for commit

git diff --cached

Alternatives:

git diff --staged

Show both staged and unstaged changes

git diff HEAD

List all branches that are already merged into master

git branch --merged master

Quickly switch to the previous branch

git checkout -

Alternatives:

git checkout @{-1}

Remove branches that have already been merged with master

git branch --merged master | grep -v '^\*' | xargs -n 1 git branch -d

Alternatives:

git branch --merged master | grep -v '^\*\|  master' | xargs -n 1 git branch -d # will not delete master if master is not checked out

List all branches and their upstreams, as well as last commit on branch

git branch -vv

Track upstream branch

git branch -u origin/mybranch

Delete local branch

git branch -d <local_branchname>

Delete remote branch

git push origin --delete <remote_branchname>

Alternatives:

git push origin :<remote_branchname>

Delete local tag

git tag -d <tag-name>

Delete remote tag

git push origin :refs/tags/<tag-name>

Undo local changes with the last content in head

git checkout -- <file_name>

Revert: Undo a commit by creating a new commit

git revert <commit-ish>

Reset: Discard commits, advised for private branch

git reset <commit-ish>

Reword the previous commit message

git commit -v --amend

See commit history for just the current branch

git cherry -v master

Amend author.

git commit --amend --author='Author Name <email@address.com>'

Reset author, after author has been changed in the global config.

git commit --amend --reset-author --no-edit

Changing a remote's URL

git remote set-url origin <URL>

Get list of all remote references

git remote

Alternatives:

git remote show

Get list of all local and remote branches

git branch -a

Get only remote branches

git branch -r

Stage parts of a changed file, instead of the entire file

git add -p

Get git bash completion

curl http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc

What changed since two weeks?

git log --no-merges --raw --since='2 weeks ago'

Alternatives:

git whatchanged --since='2 weeks ago'

See all commits made since forking from master

git log --no-merges --stat --reverse master..

Pick commits across branches using cherry-pick

git checkout <branch-name> && git cherry-pick <commit-ish>

Find out branches containing commit-hash

git branch -a --contains <commit-ish>

Alternatives:

git branch --contains <commit-ish>

Git Aliases

git config --global alias.<handle> <command>
git config --global alias.st status

Saving current state of tracked files without commiting

git stash

Alternatives:

git stash save

Saving current state of unstaged changes to tracked files

git stash -k

Alternatives:

git stash --keep-index
git stash save --keep-index

Saving current state including untracked files

git stash -u

Alternatives:

git stash save -u
git stash save --include-untracked

Saving current state with message

git stash save <message>

Saving current state of all files (ignored, untracked, and tracked)

git stash -a

Alternatives:

git stash --all
git stash save --all

Show list of all saved stashes

git stash list

Apply any stash without deleting from the stashed list

git stash apply <stash@{n}>

Apply last stashed state and delete it from stashed list

git stash pop

Alternatives:

git stash apply stash@{0} && git stash drop stash@{0}

Delete all stored stashes

git stash clear

Alternatives:

git stash drop <stash@{n}>

Grab a single file from a stash

git checkout <stash@{n}> -- <file_path>

Alternatives:

git checkout stash@{0} -- <file_path>

Show all tracked files

git ls-files -t

Show all untracked files

git ls-files --others

Show all ignored files

git ls-files --others -i --exclude-standard

Create new working tree from a repository (git 2.5)

git worktree add -b <branch-name> <path> <start-point>

Create new working tree from HEAD state

git worktree add --detach <path> HEAD

Untrack files without deleting

git rm --cached <file_path>

Alternatives:

git rm --cached -r <directory_path>

Before deleting untracked files/directory, do a dry run to get the list of these files/directories

git clean -n

Forcefully remove untracked files

git clean -f

Forcefully remove untracked directory

git clean -f -d

Update all the submodules

git submodule foreach git pull

Alternatives:

git submodule update --init --recursive
git submodule update --remote

Show all commits in the current branch yet to be merged to master

git cherry -v master

Alternatives:

git cherry -v master <branch-to-be-merged>

Rename a branch

git branch -m <new-branch-name>

Alternatives:

git branch -m [<old-branch-name>] <new-branch-name>

Rebases 'feature' to 'master' and merges it in to master

git rebase master feature && git checkout master && git merge -

Archive the master branch

git archive master --format=zip --output=master.zip

Modify previous commit without modifying the commit message

git add --all && git commit --amend --no-edit

Prunes references to remote branches that have been deleted in the remote.

git fetch -p

Alternatives:

git remote prune origin

Retrieve the commit hash of the initial revision.

 git rev-list --reverse HEAD | head -1

Alternatives:

git rev-list --max-parents=0 HEAD
git log --pretty=oneline | tail -1 | cut -c 1-40
git log --pretty=oneline --reverse | head -1 | cut -c 1-40

Visualize the version tree.

git log --pretty=oneline --graph --decorate --all

Alternatives:

gitk --all

Deploying git tracked subfolder to gh-pages

git subtree push --prefix subfolder_name origin gh-pages

Adding a project to repo using subtree

git subtree add --prefix=<directory_name>/<project_name> --squash git@github.com:<username>/<project_name>.git master

Get latest changes in your repo for a linked project using subtree

git subtree pull --prefix=<directory_name>/<project_name> --squash git@github.com:<username>/<project_name>.git master

Export a branch with history to a file.

git bundle create <file> <branch-name>

Import from a bundle

git clone repo.bundle <repo-dir> -b <branch-name>

Get the name of current branch.

git rev-parse --abbrev-ref HEAD

Ignore one file on commit (e.g. Changelog).

git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog

Stash changes before rebasing

git rebase --autostash

Fetch pull request by ID to a local branch

git fetch origin pull/<id>/head:<branch-name>

Alternatives:

git pull origin pull/<id>/head:<branch-name>

Show the most recent tag on the current branch.

git describe --tags --abbrev=0

Show inline word diff.

git diff --word-diff

Show changes using common diff tools.

git difftool -t <commit1> <commit2> <path>

Don’t consider changes for tracked file.

git update-index --assume-unchanged <file_name>

Undo assume-unchanged.

git update-index --no-assume-unchanged <file_name>

Clean the files from .gitignore.

git clean -X -f

Restore deleted file.

git checkout <deleting_commit>^ -- <file_path>

Restore file to a specific commit-hash

git checkout <commit-ish> -- <file_path>

Always rebase instead of merge on pull.

git config --global pull.rebase true

Alternatives:

#git < 1.7.9
git config --global branch.autosetuprebase always

List all the alias and configs.

git config --list

Make git case sensitive.

git config --global core.ignorecase false

Add custom editors.

git config --global core.editor '$EDITOR'

Auto correct typos.

git config --global help.autocorrect 1

Check if the change was a part of a release.

git name-rev --name-only <SHA-1>

Dry run. (any command that supports dry-run flag should do.)

git clean -fd --dry-run

Marks your commit as a fix of a previous commit.

git commit --fixup <SHA-1>

Squash fixup commits normal commits.

git rebase -i --autosquash

Skip staging area during commit.

git commit --only <file_path>

Interactive staging.

git add -i

List ignored files.

git check-ignore *

Status of ignored files.

git status --ignored

Commits in Branch1 that are not in Branch2

git log Branch1 ^Branch2

List n last commits

git log -<n>

Alternatives:

git log -n <n>

Reuse recorded resolution, record and reuse previous conflicts resolutions.

git config --global rerere.enabled 1

Open all conflicted files in an editor.

git diff --name-only | uniq | xargs $EDITOR

Count unpacked number of objects and their disk consumption.

git count-objects --human-readable

Prune all unreachable objects from the object database.

git gc --prune=now --aggressive

Instantly browse your working repository in gitweb.

git instaweb [--local] [--httpd=<httpd>] [--port=<port>] [--browser=<browser>]

View the GPG signatures in the commit log

git log --show-signature

Remove entry in the global config.

git config --global --unset <entry-name>

Checkout a new branch without any history

git checkout --orphan <branch_name>

Extract file from another branch.

git show <branch_name>:<file_name>

List only the root and merge commits.

git log --first-parent

Change previous two commits with an interactive rebase.

git rebase --interactive HEAD~2

List all branch is WIP

git checkout master && git branch --no-merged

Find guilty with binary search

git bisect start                    # Search start
git bisect bad                      # Set point to bad commit
git bisect good v2.6.13-rc2         # Set point to good commit|tag
git bisect bad                      # Say current state is bad
git bisect good                     # Say current state is good
git bisect reset                    # Finish search

Bypass pre-commit and commit-msg githooks

git commit --no-verify

List commits and changes to a specific file (even through renaming)

git log --follow -p -- <file_path>

Clone a single branch

git clone -b <branch-name> --single-branch https://github.com/user/repo.git

Create and switch new branch

git checkout -b <branch-name>

Alternatives:

git branch <branch-name> && git checkout <branch-name>

Ignore file mode changes on commits

git config core.fileMode false

Turn off git colored terminal output

git config --global color.ui false

Specific color settings

git config --global <specific command e.g branch, diff> <true, false or always>

Show all local branches ordered by recent commits

git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/

Find lines matching the pattern (regex or string) in tracked files

git grep --heading --line-number 'foo bar'

Clone a shallow copy of a repository

git clone https://github.com/user/repo.git --depth 1

Search Commit log across all branches for given text

git log --all --grep='<given-text>'

Get first commit in a branch (from master)

git log master..<branch-name> --oneline | tail -1

Unstaging Staged file

git reset HEAD <file-name>

Force push to Remote Repository

git push -f <remote-name> <branch-name>

Adding Remote name

git remote add <remote-nickname> <remote-url>

Show the author, time and last revision made to each line of a given file

git blame <file-name>

Group commits by authors and title

git shortlog

Forced push but still ensure you don't overwrite other's work

git push --force-with-lease <remote-name> <branch-name>

Show how many lines does an author contribute

git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | gawk '{ add += <!-- @doxie.inject start -->; subs += <!-- @doxie.inject end -->; loc += <!-- @doxie.inject start --> - <!-- @doxie.inject end --> } END { printf "added lines: %s removed lines: %s total lines: %s
", add, subs, loc }' -

Alternatives:

git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | awk '{ add += <!-- @doxie.inject start -->; subs += <!-- @doxie.inject end -->; loc += <!-- @doxie.inject start --> - <!-- @doxie.inject end --> } END { printf "added lines: %s, removed lines: %s, total lines: %s
", add, subs, loc }' - # on Mac OSX

Revert: Reverting an entire merge

git revert -m 1 <commit-ish>

Number of commits in a branch

git rev-list --count <branch-name>

Alias: git undo

git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'

Add object notes

git notes add -m 'Note on the previous commit....'

Show all the git-notes

git log --show-notes='*'

Apply commit from another repository

git --git-dir=<source-dir>/.git format-patch -k -1 --stdout <SHA1> | git am -3 -k

Specific fetch reference

git fetch origin master:refs/remotes/origin/mymaster

Find common ancestor of two branches

diff -u <(git rev-list --first-parent BranchA) <(git rev-list --first-parent BranchB) | sed -ne 's/^ //p' | head -1

List unpushed git commits

git log --branches --not --remotes

Alternatives:

git log @{u}..
git cherry -v

Add everything, but whitespace changes

git diff --ignore-all-space | git apply --cached

Edit [local/global] git config

git config [--global] --edit

blame on certain range

git blame -L <start>,<end>

Show a Git logical variable.

git var -l | <variable>

Preformatted patch file.

git format-patch -M upstream..topic

Get the repo name.

git rev-parse --show-toplevel

logs between date range

git log --since='FEB 1 2017' --until='FEB 14 2017'

Exclude author from logs

git log --perl-regexp --author='^((?!excluded-author-regex).*)

Generates a summary of pending changes

git request-pull v1.0 https://git.ko.xz/project master:for-linus

List references in a remote repository

git ls-remote git://git.kernel.org/pub/scm/git/git.git

Backup untracked files.

git ls-files --others -i --exclude-standard | xargs zip untracked.zip

List all git aliases

git config -l | grep alias | sed 's/^alias\.//g'

Alternatives:

git config -l | grep alias | cut -d '.' -f 2

Show git status short

git status --short --branch

Checkout a commit prior to a day ago

git checkout master@{yesterday}

Push a new local branch to remote repository and track

git push -u origin <branch_name>

⚑️ How to Contribute Here?

Make sure you follow the following simple set of rules here while trying to contribute.

  • Every Pull Request must have a title.
  • Every Pull Request must have a description.
  • Write the title and description of what you have done in the imperative mode, that is as if you were commanding someone.
    • βœ… DO: Start the line with "FIX", "ADD", "IMPROVE".
    • ❌ DON'T: Start with "Fixed", "Added", "Adding", "Improved".
    • 🎯 Read β†’ How to Write a Git Commit Message!
  • Don't end the summary line with a period - it's a title and titles don't end with a period.
  • Have fun.

This open source project is maintained by the help of awesome businesses listed below. What? Read more about it β†’

DO

🎯 License

MIT Β© Ahmad Awais

Contributors

Thanks goes to these wonderful people (emoji key):


Ahmad Awais ⚑️

πŸ“–

WPCS

πŸ“–

Iftikhar Ahmad

πŸ“–

Mr Billoo

πŸ“–

Ahmad Bilal

πŸ“–

Worwox Group

πŸ“–

A2P

πŸ“–

Alina Sofia

πŸ“–

Usman Tanvir

πŸ“–

Ahmed Zerar

πŸ“–

NidaBatool

πŸ“–

Nighat

πŸ“–

MahamBatool

πŸ“–

WPCouple

πŸ“–

WPBR

πŸ“–

Ali Raza

πŸ“–

Muhammad Umair

πŸ“–

Muhammad Arslan Aslam

πŸ“–

Pablo Rubianes

πŸ“–

Muhammad Adnan

πŸ“–

Raymond Chung

πŸ“–

MuhammadRamzan54

πŸ“–

Kustiawanto Halim

πŸ“–

Endless7188

πŸ“–

Saqib Ameen

πŸ“–

Sudais Asif

πŸ“–

Rijuth Menon

πŸ“–

LuΓ­s Melo

πŸ“–

Elias-Isaac Phiri

πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

About

πŸ™Œ #Hacktoberfest + Git Resources | Contributions beginners just like you. Jump in! 🎯

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published