Skip to content

Instantly share code, notes, and snippets.

@ppdeassis
Last active January 27, 2016 14:25
Show Gist options
  • Save ppdeassis/5628271 to your computer and use it in GitHub Desktop.
Save ppdeassis/5628271 to your computer and use it in GitHub Desktop.
Snippets for git
# init a bare repository (on a server)
mkdir repos/path.git
cd repos/path.git
git init --bare
# then, on a workstation
mkdir LOCAL_REPOS_PATH
cd LOCAL_REPOS_PATH
git init
touch .gitkeep
git add .
git commit -m "Creating repository"
git remote add origin git@SERVER:repos/path
git push origin master
# -----
# init an empty repository (on a workstation)
mkdir repos/path
cd repos/path
git init
# clone a repository
git clone <user><host>:<repos_path>
# fetch a remote branch
git fetch <remote> <rbranch>:<lbranch>
# adding a new server to the remotes
# git add remote <remote_name> <server_repos_url>
git add remote origin git@server:project.git
# create a new branch
# git checkout -b <branch_name>
git checkout -b hotfix
# merging branch hotfix in branch dev
git checkout dev
git merge hotfix
# pushing to a server
# git push <remote_name> <remote_branch_name>
git push origin dev
git push origin master
# deleting a local branch
git branch -d <branch>
# i.e. git branch -d hotfix
# deleting a remote branch
git push <remote> :<rbranch>
# i.e. git push origin :hotfix
# undo last commit
git reset --soft HEAD~1
# undo current changes in local repository
git reset --hard
# revert to a commit {
# - find the commit hash
git log
# - checkout the commit by the hash
git checkout <hash>
# note: it'll create a detached mode - checks out commit in a "new" branch)
# }
# removing all current changes
git reset --hard # current changes on staged files
git clean -f -d # untracked files
# TAGGING
# simple tag: `git tag tagname`
git tag v0.1.0
# pushing tags to remote: `git push origin tagname`
git push origin v0.1.0
# pushing all tags to remote:
git push origin --tags
# renaming a tag
# `git tag new old && git tag -d old && git push origin :refs/tags/old && git push --tags`
# example: renaming 0.1.0 to v0.1.0
git tag v0.1.0 0.1.0
git tag -d 0.1.0
git push origin :0.1.0
git push --tags
---
Configurations:
# installing meld X11 on OS X (diff toll)
brew install meld
git config --global diff.tool meld
git config --global merge.tool meld
Global gitignore:
# ref: https://help.github.com/articles/ignoring-files/#create-a-global-gitignore
# create it at ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment