34 examples for git

{{ score }}
  # Delete last commit
git reset --hard HEAD~1
        
{{ score }}
  # Setup git global configuration 
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git config --global core.editor vim
        
{{ score }}
  # git init creates a .git directory in the current folder.
git init
        
{{ score }}
  # Create and check out a new branch
git checkout -b mybranch
        
{{ score }}
  # Paginate - useful for creating commits of specific changes
git add -p
        
{{ score }}
  # allows you to commit your changes with a message detailing what you have changed
git commit -m "Fixed unit test"
        
{{ score }}
  # pick range commits  
git cherry-pick [commit id]
        
{{ score }}
  # Checkout Subversion repository in standard layout (branches, tags, trunk) using Git
git svn clone svn://example.org/path/to/repo targetdir -s --prefix=origin/ [--no-minimize-url] [--authors-file=/path/to/authors.txt]
        
{{ score }}
  # cleaning up old remote git branches
git remote prune origin
        
{{ score }}
  # Show diff of staged changed
git diff --cached
        
{{ score }}
  # Delete remote branch (git v1.7.0 and up)
git push origin --delete feature_branch
        
{{ score }}
  # Initiates an bare repository in current directory. 
git --bare init .
        
{{ score }}
  # a better alternative to git pull, won't commit merge conflicts 
!git remote update -p; git merge --ff-only @{u}
        
{{ score }}
  # Shows the URL of the github project (run this command inside the project directory)
git remote get-url origin
        
{{ score }}
  # create a git alias, now git ci "message" is a command
git config --global alias.ci 'commit -m'
        
{{ score }}
  # checkout a specific tag
git checkout tags/
        
{{ score }}
  # When the "assume unchanged" bit is on, Git stops checking the working tree files for possible modifications, undo with --no-assume-unchanged
git update-index --assume-unchanged 
        
{{ score }}
  # Delete local branch
git branch -D feature_branch
        
{{ score }}
  # Look for occurrences of word 'foo' in diffs
git log -Gfoo
        
{{ score }}
  # Rename current branch branch
git branch -m 
        
{{ score }}
  # Remove all untracked files and directories 
git clean -df
        
{{ score }}
  # Delete (one of the) last commit(s) without shooting yourself in the foot
# In the editor that opens, remove the line of any commit you want to discard.
# Only shows commits not pushed to upstream, thus avoids trouble later on.
git rebase -i
        
{{ score }}
  # Remove changes in patches
git checkout -p
        
{{ score }}
  # ignore filemode changes
git config core.fileMode false
        
{{ score }}
  # Show file change statistics (additions/subtractions per file)
git diff --stat
        
{{ score }}
  # Show log with file change statistics (additions/subtractions per file)
git log --stat
        
{{ score }}
  # See git log entries along with their code changes
git log -p
        
{{ score }}
  # add remote https
git remote add origin https://server/user/repo.git

# add remote ssh
git remote add origin git@server:user/repo.git
        
{{ score }}
  # Amend commit and change author name
git commit --amend --reset-author
        
{{ score }}
  # Push new local branch named newbranch to remote repository named origin
git push -u origin newbranch
        
{{ score }}
  # Show diff of one file
git diff --js/main.js
        
{{ score }}
  # Push local committed changes to main repository
git push origin master
        
{{ score }}
  # allows you to save changes, and will first show changes which are to be made, and will prompt you to write a description of the changes.
git commit
        
{{ score }}
  # stages files in current dir and sub-directories (unless they are excluded in the .gitignore).
git add *