Last active
November 30, 2015 01:25
-
-
Save rolandovillca/e0092f606a189d1fd03a to your computer and use it in GitHub Desktop.
GIT COMMANDS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CHECKOUT BRANCH | |
$ checkout branch -f | |
$ git pull | |
# CHECK CHANED FILES IN GIT COMMIT: | |
$ git log | |
$ git log -p -2 | |
$ git log --pretty=oneline | |
$ git log --name-only | |
$ git log -1 --stat | |
$ git log --graph | |
$ git log --graph --oneline | |
$ git log --graph --oneline --branches | |
$ git show --pretty="format:" --name-only 6ef288287c49e21062d8a9d9561d8f4a635bbf15 | |
$ git show --summary | |
# or | |
$ git diff-tree --no-commit-id --name-only -r 7dc1fc210f9608e3eacdcb4f9549cf84379a3ff6 | |
# Notes: | |
# The --no-commit-id suppresses the commit ID output. | |
# The --pretty argument specifies an empty format string to avoid the cruft at the beginning. | |
# The --name-only argument shows only the file names that were affected (Thanks Hank). | |
# The -r argument is to recurse into sub-trees | |
# MOVE FILES TO ANOTHER DIRECTORY: | |
$ mkdir lib | |
$ git mv hello.html lib | |
$ git status | |
# DIFFERENCE BETWEEN git pull AND git fetch: Fetching and Pulling from Your Remotes | |
# git fetch command pulls the data to your local repository – it doesn’t automatically merge it with any of your work or modify what you’re currently working on. You have to merge it manually into your work when you’re ready. | |
# git pull command to automatically 'git fetch' and then 'git merge' a remote branch into your current branch. | |
# UNDO 'git add' BEFORE COMMIT: | |
# I mistakenly added files using the command: | |
$ git add filename | |
# Undo git add before commit with: | |
$ git reset filename | |
# To remove everything and start again (recursive): | |
$ git rm -r --cached . | |
# To do a dry run and see what will be added: | |
$ git add -n . | |
# To remove a file from the repo and not delete it from the local file system: | |
# 1. For a file: | |
$ git rm --cached file.txt | |
# 2. For a directory: | |
$ git rm --cached -r mydirectory | |
# To remove a file from de repo but also deletes it from the local file system: | |
$ git rm file1.txt | |
$ git commit -m "remove file1.txt" | |
# How to convert a normal Git repository to a bare one? | |
$ cd repo | |
$ mv .git .. && rm -fr * | |
$ mv ../.git . | |
$ mv .git/* . | |
$ rmdir .git | |
$ git config --bool core.bare true | |
$ cd ..; mv repo repo.git # renaming just for clarity | |
# Note that this is different from doing a git clone --bare to a new location (see below). | |
# ADDING REMOTE REPOSITORY: | |
$ git remote | |
origin | |
$ git remote add pb https://github.com/paulboone/ticgit | |
$ git remote -v | |
# PUSHING TO REMOTE REPO: | |
$ git push <remote_name> <branch_name> | |
$ git push origin master | |
# INSPECTING REMOTE: | |
$ git remote show origin | |
$ git remote | |
$ git remote -v | |
# REMOVING AND RENAMING REMOTES: | |
# I want to rename pb to paul: | |
$ git remote rename pb paul | |
$ git remote | |
origin | |
paul | |
# NOTE: It’s worth mentioning that this changes your remote branch names, too. | |
# What used to be referenced at pb/master is now at paul/master. | |
# If you want to remove a remote for some reason | |
$ git remote rm paul | |
$ git remote | |
origin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment