π Hacktoberfest
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 β
π About Hacktoberfest:
What is Hacktoberfest?
Hacktoberfest is a month-long celebration of open source software run by DigitalOcean in partnership with GitHub and Dev.
- Hacktoberfest is open to everyone in our global community!
- Four quality pull requests must be submitted to public GitHub repositories.
- You can sign up anytime between October 1 and October 31.
2024
π Git Resources:
Listing a few git resources here for everyone.
β‘οΈ Git Basics:
β‘οΈ Git Tutorials:
There are tons of learning material on the Web
- Try Git β learn Git in 15 minutes with pseudo-terminal interface
- How to Create a Pull Request β learn to create a GitHub Pull Request
- GitHub Learning Paths β learn about Git, Setup, GitHub, and a lot more
- Atlassian Git Tutorial β comprehensive tutorial on Git
- Use gitk to understand git β all important Git terms (commit, commit SHA, branch, merge, rebase) explained using gitk
- Learn Version Control with Git β freemium ebook from fournova Software (makers for Tower), associated with paid video course
- Learn Enough Git to Be Dangerous - a tutorial on version control with git
- Pro Git β free Git book (CC BY-NC-SA 3.0)
- The Git Community Book β book built by dozens of people in the Git community
- Git Pocket Guide β a short O'Reilly book on Git
- Git Real: Code School β paid training course from Code School
- Git Branching β visual way to learn git branching
- Learn Git in a Month of Lunches β tutorial-based book by Manning Publications
- Git Magic β short book about Git
- Git from the bottom up β great series of articles about Git
- Git-it β app-tutorial on Git
- Learn Git - Codecademy β This course will show you basic workflow and core features, different ways to undo changes or save multiple versions of a project, and how to collaborate with other developers
- Migrating to Git LFS β Use Git LFS on an existing repository to manage large files in a better way
- Learn Git Branching β Interactive way to learn how git branching works
- An Introduction to Git and GitHub by Brian Yu - CS 50 Git Tutorial
- Version Control with Git β The essentials of using the version control system Git
- GitHub & Collaboration β The essentials of working with remote repositories
- How to Use Git and GitHub β Effective use of version control
- Getting Started with Git
- Learn to Manage Code Based Projects and Collaborate Using GitHub
- Introduction to Git by DataCamp
- Become an Expert in Git & GitHub in 4 Hours
β‘οΈ 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
- GitUp β a clean, minimal Git client. Mac only.
- GitExtensions β a shell extension, a Visual Studio 2010-2015 plugin and a standalone Git repository tool.
- Octotree β a must-have browser extension to explore code on GitHub
- Tig - text-mode interface for Git
- Sublime Merge - a cross-platform Git client from the makers of Sublime Text.
- Gitless - an experimental version of Git that changes some of Git's underlying concepts
- ghq β Organization for remote repositories
- bash-git-prompt - An informative and fancy bash prompt for Git users
β‘οΈ 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
- GitLens - A Visual Studio code extension which helps you visualize code authorship at a glance via Git blame annotations and code lens. Allows you to seamlessly explore Git repositories and gain valuable insights via powerful comparison commands.
β‘οΈ 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
- SourceForge β a long-standing free Git repository hosting service
β‘οΈ 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.
- Gitea - a community managed fork of Gogs
- 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
- husky - Git hooks for Node.js, manage your hooks from your package.json
:octocat: 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 -- :computer: :mortar_board: 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 :boom: 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.
- Fun with GitHub β A fun overview of 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
Configuration management
DigitalOcean Developer documentation
GitHub
Open source projects
Editors
Community OSS projects
- do-sshuttle - Transparent Proxying via sshuttle to DigitalOcean Droplet.
- drophosts - Update
/etc/hosts
with peer droplets.
- droplan - Manage iptable rules for the private interface on DigitalOcean droplets.
- foreman-digitalocean - Plugin to enable management of DigitalOcean droplets in Foreman.
- lita-digitalocean - Lita handler for managing DigitalOcean services.
- DDNS - Personal DDNS client with DigitalOcean Networking DNS as backend.
- Less Confusing Menus - A Chrome extension that makes account menus less confusing.
- DigitalOcean Droplet creator - A dialog-based shell script to quickly create a single DigitalOcean Droplet.
- do-upgrade-plans - A script to upgrade your DigitalOcean Droplets to better plans with the same cost.
Clients
- doctl - Command-line tool for DigitalOcean services.
- digitalocean-indicator - Debian Gnome panel client.
- domanager - Linux and Windows System Tray Client.
- OceanBar - macOS menu bar client.
- Tugboat - Ruby command-line tool for DigitalOcean services, focusing on a more guided UX.
DigitalOcean Community
β‘οΈ 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
Show git log with beautiful graph tree (adog)
$ git log --all --decorate --oneline --graph
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>
Merge branch without fast forward (keeps the notion of explicit branches):
$ git merge --no-ff <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
10 Simple steps to contribute to any existing open source project on Github:
1) First of all choose a project you want to contribute to.
2) Go to the repository on Github page.
3) Press the βforkβ button on the right side.
4) Press the βCloneβ button to clone that project.
5) Create a new branch and push it.
6) Make all the changes on that new branch.
7) Commit all the changes to that new and push them.
8) Now go to that existing project and create a pull request by pressing the compare and pull request button.
9) Congratulations your job is done :).
10) Now the people maintaining that branch will review those changes and merge them.
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 flow schema
squash
$ git squash fixed-cursor-styling "Fixed cursor styling"
$ git squash 95b7c52
$ git squash HEAD~3
summary
$ git summary
project : git
repo age : 10 years
active : 11868 days
commits : 40530
files : 2825
authors :
15401 Junio C Hamano 38.0%
1844 Jeff King 4.5%
line-summary
$ git line-summary
project : gulp
lines : 3900
authors :
1040 Contra 26.7%
828 Sindre Sorhus 21.2%
effort
$ git effort
file commits active days
.gitattributes............................... 3 3
.gitignore................................... 265 226
.mailmap..................................... 47 40
authors
$ git authors
Contra <contra@maricopa.edu>
Eric Schoffstall <contra@wearefractal.com>
Sindre Sorhus <sindresorhus@gmail.com>
changelog
$ git changelog
## 3.9.0
- add babel support
- add transpiler fallback support
- add support for some renamed transpilers (livescript, etc)
- add JSCS
- update dependecies (liftoff, interpret)
- documentation tweaks
## 3.8.11
- fix node 0.12/iojs problems
- add node 0.12 and iojs to travis
- update dependencies (liftoff, v8flags)
- documentation tweaks
commits-since
$ git commits-since yesterday
... changes since yesterday
TJ Holowaychuk - Fixed readme
count
$ git count
total 855
create-branch
$ git create-branch development
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/tj/git-extras.git
* [new branch] HEAD -> development
Branch development set up to track remote branch development from origin.
Switched to a new branch 'development'
delete-submodule
$ git delete-submodule lib/foo
delete-tag
$ git delete-tag v0.1.1
Deleted tag 'v0.1.1' (was 9fde751)
To https://github.com/tj/git-extras.git
- [deleted] v0.1.1
delete-merged-branches
$ git delete-merged-branches
Deleted feature/themes (was c029ab3).
Deleted feature/live_preview (was a81b002).
Deleted feature/dashboard (was 923befa).
fresh-branch
$ git fresh-branch docs
Removing .DS_Store
Removing .editorconfig
Removing .gitignore
guilt
$ git guilt `git log --until="3 weeks ago" --format="%H" -n 1` HEAD
Paul Schreiber +++++++++++++++++++++++++++++++++++++++++++++(349)
spacewander +++++++++++++++++++++++++++++++++++++++++++++(113)
Mark Eissler ++++++++++++++++++++++++++
merge-into
$ git merge-into master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
Updating 9fde751..e62edfa
Fast-forward
234 | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 234
Switched to branch 'development'
graft
$ git graft development
Your branch is up-to-date with 'origin/master'.
Merge made by the 'recursive' strategy.
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Deleted branch development (was 64b3563).
alias
$ git alias last "cat-file commit HEAD"
$ git alias
last = cat-file commit HEAD
ignore
$ git ignore build "*.o" "*.log"
... added 'build'
... added '*.o'
... added '*.log'
info
$ git info
## Remote URLs:
origin git@github.com:sampleAuthor/git-extras.git (fetch)
origin git@github.com:sampleAuthor/git-extras.git (push)
## Remote Branches:
origin/HEAD -> origin/master
origin/myBranch
## Local Branches:
myBranch
* master
## Most Recent Commit:
commit e3952df2c172c6f3eb533d8d0b1a6c77250769a7
Author: Sample Author <sampleAuthor@gmail.com>
Added git-info command.
Type 'git log' for more commits, or 'git show <commit id>' for full commit details.
## Configuration (.git/config):
color.diff=auto
color.status=auto
fork
$ git fork LearnBoost/expect.js
release
$ git release 0.1.0
... releasing 0.1.0
On branch development
Your branch is up-to-date with 'origin/development'.
nothing to commit, working directory clean
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/tj/git-extras.git
9fde751..e62edfa master -> master
Counting objects: 1, done.
Writing objects: 100% (1/1), 166 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/tj/git-extras.git
* [new tag] 0.1.0 -> 0.1.0
... complete
contrib
$ git contrib visionmedia
visionmedia (18):
Export STATUS_CODES
Replaced several Array.prototype.slice.call() calls with Array.prototype.unshift.call()
Moved help msg to node-repl
repl
$ git repl
git> ls-files
History.md
Makefile
undo
$ git undo
Unstaged changes after reset:
M package.json
M readme.md
gh-pages
$ git gh-pages
scp
$ git scp staging HEAD
setup
$ git setup
Initialized empty Git repository in /GitHub/test/gulp/.git/
[master (root-commit) 9469797] Initial commit
69 files changed, 3900 insertions(+)
create mode 100644 .editorconfig
create mode 100644 .gitignore
create mode 100644 .jscsrc
touch
$ git touch index.js
obliterate
$ git obliterate secrets.json
Rewrite 2357a4334051a6d1733037406ab7538255030d0b (1/981)rm 'secrets.json'
Rewrite b5f62b2746c23150917d346bd0c50c467f01eb03 (2/981)rm 'secrets.json'
Rewrite 3cd94f3395c2701848f6ff626a0a4f883d8a8433 (3/981)rm 'secrets.json'
feature|refactor|bug|chore
$ git feature dependencies
$ git feature finish dependencies
Already up-to-date.
Deleted branch feature/dependencies (was f0fc4c7).
Deleted remote-tracking branch origin/feature/dependencies (was f0fc4c7).
To git@github.com:stevemao/gulp.git
- [deleted] feature/dependencies
local-commits
$ git local-commits
commit 5f00a3c1bb71876ebdca059fac96b7185dea5467
Merge: 7ad3ef9 841af4e
Author: Blaine Bublitz <blaine@iceddev.com>
Date: Thu Aug 20 11:35:15 2015 -0700
Merge pull request #1211 from JimiHFord/patch-1
Update guidelines.md
commit 841af4ee7aaf55b505354d0e86d7fb876d745e26
Author: Jimi Ford <JimiHFord@users.noreply.github.com>
Date: Thu Aug 20 11:55:38 2015 -0400
Update guidelines.md
fixed typo
archive-file
$ git archive-file
Building archive on branch "master"
Saved to "gulp.v3.9.0-36-g47cb6b0.zip" ( 60K)
missing
$ git missing master
< d14b8f0 only on current checked out branch
> 97ef387 only on master
lock
$ git lock config/database.yml
locked
$ git locked
config/database.yml
unlock
$ git unlock config/database.yml
reset-file
$ git reset-file README.md HEAD^
Reset 'README.md' to HEAD^
pr
$ git pr 226
From https://github.com/tj/git-extras
* [new ref] refs/pulls/226/head -> pr/226
Switched to branch 'pr/226'
root
$ git root
/GitHub/git
delta
$ git delta
README.md
merge-repo
$ git merge-repo git@github.com:tj/git-extras.git master .
git fetch git@github.com:tj/git-extras.git master
warning: no common commits
remote: Counting objects: 3507, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 3507 (delta 1), reused 0 (delta 0), pack-reused 3502
Receiving objects: 100% (3507/3507), 821.12 KiB | 286.00 KiB/s, done.
Resolving deltas: 100% (1986/1986), done.
From github.com:tj/git-extras
* branch master -> FETCH_HEAD
Added dir 'git-merge-repo.E95m0gj'
No local changes to save
psykorebase
$ git psykorebase master
$ git psykorebase --continue
$ git psykorebase master feature
flow init
$ git flow init
Which branch should be used for bringing forth production releases?
- changelog
- master
Branch name for production releases: [master]
Which branch should be used for integration of the "next release"?
- changelog
Branch name for "next release" development: [master]
Production and integration branches should differ.
flow feature
$ git flow feature
$ git flow feature start awesome-feature
$ git flow feature finish awesome-feature
$ git flow feature delete awesome-feature
$ git flow feature publish awesome-feature
$ git flow feature pull remote awesome-feature
flow release
$ git flow release
$ git flow release start awesome-release
$ git flow release finish awesome-release
$ git flow release delete awesome-release
flow hotfix
$ git flow hotfix
$ git flow hotfix start awesome-release
$ git flow hotfix finish awesome-release
$ git flow hotfix delete awesome-release
flow support
$ git flow support
$ git up
Fetching origin
4.0 fast-forwarding...
changelog ahead of upstream
master fast-forwarding...
returning to 4.0
clone
$ git clone schacon/ticgit
> git clone git://github.com/schacon/ticgit.git
$ git clone -p schacon/ticgit
> git clone git@github.com:schacon/ticgit.git
$ git clone resque
> git clone git@github.com/YOUR_USER/resque.git
remote add
$ git remote add rtomayko
> git remote add rtomayko git://github.com/rtomayko/CURRENT_REPO.git
$ git remote add -p rtomayko
> git remote add rtomayko git@github.com:rtomayko/CURRENT_REPO.git
$ git remote add origin
> git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git
fetch
$ git fetch mislav
> git remote add mislav git://github.com/mislav/REPO.git
> git fetch mislav
$ git fetch mislav,xoebus
> git remote add mislav ...
> git remote add xoebus ...
> git fetch --multiple mislav xoebus
cherry-pick
$ git cherry-pick https://github.com/mislav/REPO/commit/SHA
> git remote add -f --no-tags mislav git://github.com/mislav/REPO.git
> git cherry-pick SHA
$ git cherry-pick mislav@SHA
> git remote add -f --no-tags mislav git://github.com/mislav/CURRENT_REPO.git
> git cherry-pick SHA
$ git cherry-pick mislav@SHA
> git fetch mislav
> git cherry-pick SHA
am
$ git am https://github.com/github/hub/pull/55
[ downloads patch via API ]
> git am /tmp/55.patch
$ git am --ignore-whitespace https://github.com/davidbalbert/hub/commit/fdb9921
[ downloads patch via API ]
> git am --ignore-whitespace /tmp/fdb9921.patch
apply
$ git apply https://gist.github.com/8da7fb575debd88c54cf
[ downloads patch via API ]
> git apply /tmp/gist-8da7fb575debd88c54cf.txt
fork
$ git fork
[ repo forked on GitHub ]
> git remote add -f YOUR_USER git@github.com:YOUR_USER/CURRENT_REPO.git
pull-request
$ git pull-request
[ opens text editor to edit title & body for the request ]
[ opened pull request on GitHub for "YOUR_USER:feature" ]
checkout
$ git checkout https://github.com/github/hub/pull/73
> git remote add -f --no-tags -t feature mislav git://github.com/mislav/hub.git
> git checkout --track -B mislav-feature mislav/feature
merge
$ git merge https://github.com/github/hub/pull/73
> git fetch git://github.com/mislav/hub.git +refs/heads/feature:refs/remotes/mislav/feature
> git merge mislav/feature --no-ff -m 'Merge pull request #73 from mislav/feature...'
create
$ git create
[ repo created on GitHub ]
> git remote add origin git@github.com:YOUR_USER/CURRENT_REPO.git
init
$ git init -g
> git init
> git remote add origin git@github.com:YOUR_USER/REPO.git
push
$ git push origin,staging,qa bert_timeout
> git push origin bert_timeout
> git push staging bert_timeout
> git push qa bert_timeout
browse
$ git browse
> open https://github.com/YOUR_USER/CURRENT_REPO
compare
$ git compare refactor
> open https://github.com/CURRENT_REPO/compare/refactor
submodule
$ git submodule add wycats/bundler vendor/bundler
> git submodule add git://github.com/wycats/bundler.git vendor/bundler
ci-status
$ git ci-status
success
β‘οΈ 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
- Show helpful guides that come with Git
- Search change by content
- Sync with remote, overwrite local changes
- List of all files till a commit
- Git reset first commit
- List all the conflicted files
- List of all files changed in a commit
- Unstaged changes since last commit
- Changes staged for commit
- Show both staged and unstaged changes
- List all branches that are already merged into master
- Quickly switch to the previous branch
- Remove branches that have already been merged with master
- List all branches and their upstreams, as well as last commit on branch
- Track upstream branch
- Delete local branch
- Delete remote branch
- Delete local tag
- Delete remote tag
- Undo local changes with the last content in head
- Revert: Undo a commit by creating a new commit
- Reset: Discard commits, advised for private branch
- Reword the previous commit message
- See commit history for just the current branch
- Amend author.
- Reset author, after author has been changed in the global config.
- Changing a remote's URL
- Get list of all remote references
- Get list of all local and remote branches
- Get only remote branches
- Stage parts of a changed file, instead of the entire file
- Get git bash completion
- What changed since two weeks?
- See all commits made since forking from master
- Pick commits across branches using cherry-pick
- Find out branches containing commit-hash
- Git Aliases
- Saving current state of tracked files without commiting
- Saving current state of unstaged changes to tracked files
- Saving current state including untracked files
- Saving current state with message
- Saving current state of all files (ignored, untracked, and tracked)
- Show list of all saved stashes
- Apply any stash without deleting from the stashed list
- Apply last stashed state and delete it from stashed list
- Delete all stored stashes
- Grab a single file from a stash
- Show all tracked files
- Show all untracked files
- Show all ignored files
- Create new working tree from a repository (git 2.5)
- Create new working tree from HEAD state
- Untrack files without deleting
- Before deleting untracked files/directory, do a dry run to get the list of these files/directories
- Forcefully remove untracked files
- Forcefully remove untracked directory
- Update all the submodules
- Show all commits in the current branch yet to be merged to master
- Rename a branch
- Rebases 'feature' to 'master' and merges it in to master
- Archive the
master
branch
- Modify previous commit without modifying the commit message
- Prunes references to remote branches that have been deleted in the remote.
- Retrieve the commit hash of the initial revision.
- Visualize the version tree.
- Deploying git tracked subfolder to gh-pages
- Adding a project to repo using subtree
- Get latest changes in your repo for a linked project using subtree
- Export a branch with history to a file.
- Import from a bundle
- Get the name of current branch.
- Ignore one file on commit (e.g. Changelog).
- Stash changes before rebasing
- Fetch pull request by ID to a local branch
- Show the most recent tag on the current branch.
- Show inline word diff.
- Show changes using common diff tools.
- Donβt consider changes for tracked file.
- Undo assume-unchanged.
- Clean the files from
.gitignore
.
- Restore deleted file.
- Restore file to a specific commit-hash
- Always rebase instead of merge on pull.
- List all the alias and configs.
- Make git case sensitive.
- Add custom editors.
- Auto correct typos.
- Check if the change was a part of a release.
- Dry run. (any command that supports dry-run flag should do.)
- Marks your commit as a fix of a previous commit.
- Squash fixup commits normal commits.
- Skip staging area during commit.
- Interactive staging.
- List ignored files.
- Status of ignored files.
- Commits in Branch1 that are not in Branch2
- List n last commits
- Reuse recorded resolution, record and reuse previous conflicts resolutions.
- Open all conflicted files in an editor.
- Count unpacked number of objects and their disk consumption.
- Prune all unreachable objects from the object database.
- Instantly browse your working repository in gitweb.
- View the GPG signatures in the commit log
- Remove entry in the global config.
- Checkout a new branch without any history
- Extract file from another branch.
- List only the root and merge commits.
- Change previous two commits with an interactive rebase.
- List all branch is WIP
- Find guilty with binary search
- Bypass pre-commit and commit-msg githooks
- List commits and changes to a specific file (even through renaming)
- Clone a single branch
- Create and switch new branch
- Ignore file mode changes on commits
- Turn off git colored terminal output
- Specific color settings
- Show all local branches ordered by recent commits
- Find lines matching the pattern (regex or string) in tracked files
- Clone a shallow copy of a repository
- Search Commit log across all branches for given text
- Get first commit in a branch (from master)
- Unstaging Staged file
- Force push to Remote Repository
- Adding Remote name
- Show the author, time and last revision made to each line of a given file
- Group commits by authors and title
- Forced push but still ensure you don't overwrite other's work
- Show how many lines does an author contribute
- Revert: Reverting an entire merge
- Number of commits in a branch
- Alias: git undo
- Add object notes
- Show all the git-notes
- Apply commit from another repository
- Specific fetch reference
- Find common ancestor of two branches
- List unpushed git commits
- Add everything, but whitespace changes
- Edit [local/global] git config
- blame on certain range
- Show a Git logical variable.
- Preformatted patch file.
- Get the repo name.
- logs between date range
- Exclude author from logs
- Generates a summary of pending changes
- List references in a remote repository
- Backup untracked files.
- List all git aliases
- Show git status short
- Checkout a commit prior to a day ago
- Push a new local branch to remote repository and track
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
Undos last commit but files are still staged
git reset --soft HEAD
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.
- 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 β
π― License
MIT Β© Ahmad Awais
Contributors
For anything else, tweet at @MrAhmadAwais