On Github tushar-rishav / EPGit
Having the entire history of the project in a single place, we risk losing everything.
Created by Linus Torvalds and the Linux development community.
Git Commands
git configs
$ git help # Your git manual page. $ git config --global user.name "Tushar Gautam" $ git config --global user.email tushar.rishav@gmail.com
Default text editor for git. In my case vim
$ git config --global core.editor vim
See complete list
$ git config --list
Git Commands
git init <directory> # leaving `directory` will initialis a repo # in the current directory.
git clone <repo-url> [<target-directory> # creates a directory called "coala". git clone https://github.com/coala-analyzer/coala.git # creates a directory called "my-directory" git clone https://github.com/coala-analyzer/coala.git my-directory
File status
$ git add <file-name> # Add `file-name` to staging area. $ git status # check status for files. $ git status -s # same as above but less verbose.
File status
$ git diff # To see what you’ve changed but not yet staged, $ git diff --staged $ git diff --cached # same as above # To see what have been staged that will go into next commit, # compares the staged changes to last commit.
Git Commit
$ git commit # Opens default editor with output from `git status` $ git commit -v # Similar but displays `diff` for the changes. $ git commit -m "commit message" # Inline. $ git commit -am "commit message" $ git show <commit_hash> # default is recent commit. # Skip staging area and commit all changed files. Careful! $ git rm <file> # remove `file` from staging area and the filesystem. $ git rm --cached <file> # remove from staging area only.
Git Log or History
$ git log # Lists all commits with most recent commits show up first. $ git log -p # Shows diffs introduced with each commit. $ git log -p -3 # Show first 3 entries only. $ git log --oneline # Less verbose. $ git log --graph --oneline. # Shows graphical structure for branch and merge history. $ git log --help # for more options.
Make changes
$ git commit --amend # Change the last commit message. $ git checkout <commit_hash> # checkout to the repo state wrt to the commit. $ git checkout -- <file> # Drop the changes for `file`. Careful!
Remote
$ git remote -v # List all remotes with their urls. $ git remote add <name | alias> <url> # add remote. $ git remote rename <old-name> <new-name> # rename remote. $ git remote set-url <name> <url> # change the url for a remote. $ git remote rm <name> # remove remote. $ git fetch <remote-name> # fetch from remote. # ^ Only downloads the data and not merge or modifies. $ git merge # merge the changes. $ git pull # fetch + merge $ git push <remote-name> <branch-name> # use `-f` to force push.
Workflow
Add remote. Create branch. Add/Make changes and commit. Fetch from remote and rebase. Push or force push. Create a pull request.We have talked about all except 6 and 7.
$ git fetch <remote-name> $ git rebase -i <remote/branch-name> $ git request-pull [-p] <start> <url> [<end>] # Use git request-pull and a mailing list. eg. Linux kernel.
Branching
$ git branch # display branch $ git branch -a # all branch $ git branch <new-branch> # create a new branch. $ git checkout <new-branch> # Checkout to new branch. $ git checkout -b <other-new-branch> # Combines above two. $ git checkout -D <brnach-name> # Force delete branch with unmerged changes.
$ git merge # merge changes from feature to master $ git rebase $ git rebase -i # interactive rebase.
Cherry-pick
$ git cherry-pick <commit_hash> $ git revert $ git reset HEAD # HEAD means current commit $ git reset --hard HEAD # Move branch pointer to certain commit state
Let's start the contribution process :)