Tuesday, February 6, 2018

git reminder

# Git command summary

## Copy a repo locally

```bash
 git clone url
``` 

## Status

 git status

## Get latest of develop branch:

 git pull
 git fetch -all
 git merge origin/develop

## Branch

```bash
 # Create
 git checkout -b BRANCH-NAME
 # Switch
 git checkout BRANCH-NAME
 # Rename a local branch
 git branch -m BRANCH-NAME BRANCH-NAME
 # Last commits on each branch
 git branch -v
 # Which branches are already merged into the branch you’re on
 git branch --merged
```

# Editor and merge tool

```bash
 # Set up editor:
 git config --global core.editor notepad
 # Set up a diff tool:
 # https://sourceforge.net/projects/kdiff3/files/
 # kdiff3.exe must be in the path
 git config --global merge.tool kdiff3
``` 

# undo commited change ahead of remote
git reset --soft HEAD~1

## Undo

```bash
 # Undo unstaged changes
 git checkout .
 git checkout /folder/file.js
 # Undo unstaged and staged changes
 git reset --hard 
 # Undo change commite in the wrong branch, but keep the changes
 git log # to find the hash for the change
 git reset --mixed 2c41838da2738c0e1e23336fe48c3e4bae10d5f6
 # Revert a change that you have committed
 git revert  
 # Remove untracked files (new files)
 git clean -f
```

# How to change temporary changes - Stash (Selveset)
```bash
 git stash
 git pull
 git branch -m FredBundleStudy
 git stash pop
``` 

#How to delete a repo locally?

```bash
c:\myFolder> attrib -s -h -r . /s /d
c:\myFolder> del /F /S /Q /A .git
c:\myFolder> rmdir .git
```

No comments:

Post a Comment