An open API service indexing awesome lists of open source software.

https://github.com/hackjutsu/cheatsheet


https://github.com/hackjutsu/cheatsheet

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

# Quick Reference for Git Commands

**Set up a new repository**

```bash
git init
git pull https://github.com/registercosmo/Cheatsheet.git
git remote add origin https://github.com/registercosmo/Cheatsheet.git
git add .
git status
git commit
git commit -m "comments"
git push -u origin master
```

**Sync with the remote repository**

```bash
# To pull changes to workspace (= fetch + merge)
git pull origin master

# To fetch lastest changes from other developers to local repo
git fetch

# To merge the local repo and the workspace
git merge origin master
```

**Fix the previous commit**

```bash
git commit --amend
```

**Undo changes**

```bash
# unstage changes but keep the local changes in the working space
git reset HEAD

# discard all the changes in the stage and working space, and match the working space the commit B
git reset --hard B

# move the HEAD to commit B, no modification will be made to the stage and the working space
git reset --soft B
```

**Untrack files**

```bash
git rm --cached
```

**Set up remote repositories**

```bash
# set up a new remote repo (origin)
git remote add origin

# change URL for a remote repo (origin)
git remote set-url origin

# list all the remote repositories URLs
git remote -v
```

**About Configs**

```bash
# configurations for all repositories
git config --global user.name # check current global user.name
git config --global user.name
git config --gloabl user.email=myemail@example.com

# configurations for local repository
git config user.name # check current local user.name
git config user.name
git config -user.email=myemail@example.com

# list all the configs
git config --list

# Remove the configs
git config --global --unset-all user.name # global

# Change the configs
git config --global --replace-all user.name # global
```

**About Branches**

```bash
# fetch remote branches from Github
git remote add origin # we have to set origin first
git pull # It will pull(fetch + merge) all available branches from repositories

# check info for all available branches
git branch

# create a new branch
git branch

# switch to a specific branch
git checkout

# create and switch to a new branch
git checkout -b

# check the current branch
git status

# rename a branch
git branch -m

# merge a specific branch to the current branch
git merge

# delete a branch locally
git branch -d

# delete a branch remotely
git push origin :
```

**About diff**

```bash
# inspect all the modifications between workspace and stage
git diff

# inspect all the modifications between stage and local repo
git diff --cached
```

**About resolving conflicts**

```bash
git add
```

**Advanced Topics**

```bash
# get the SHA-1 key for a specific contents
echo 'test content' | git hash-object -w --stdin

# get the content of a SHA-1 key
git cat-file -p

# get a object type for a SHA-1 key
git cat-file -t
```