GIT BASICS

CREATE, LOCAL CHANGES, COMMIT HISTORY, BRANCHES AND TAGS, UPDATE AND PUBLISH, MERGE AND REBASE, UNDO
0

GIT

MEDIUM

last hacked on Jul 25, 2018

# Create Clone existing repository: ``` git clone <repository> ``` Replace `<repository>` with the HTTPS or SSH path to the repository you'd like to clone. For example, try: ``` git clone git@github.com:muschellij2/Neurohacking_data.git ``` Create new local repository: ``` git init ``` # Local Changes View changed files in working directory: ``` git status ``` View changes of tracked files: ``` git diff ``` Add all current changes to the next commit: ``` git add . ``` Add changes in `<file>` to the next commit: ``` git add -p <file> ``` ``` git commit -a ``` ``` git commit ``` ``` git commit --amend ``` # Commit History ``` git log ``` ``` git log -p <file> ``` ``` git blame <file> ``` # Branches & Tags ``` git branch -av ``` ``` git checkout <branch> ``` ``` git branch <new-branch> ``` ``` git checkout -- track <remote/branch> ``` ``` git branch -d <branch> ``` ``` git tag <tag-name> ``` # Update & Publish ``` git remote -v ``` ``` git remote show <remote> ``` ``` git remote add <shortname> <url> ``` ``` git fetch <remote> ``` ``` git pull <remote> <branch> ``` ``` git push <remote> <branch> ``` ``` git branch -dr <remote/branch> ``` ``` git branch -dr <remote/branch> ``` ``` git push --tags ``` # Merge & Rebase ``` git merge <branch> ``` ``` git pull --rebase ``` ``` git rebase <branch> ``` ``` git rebase --abort ``` ``` git rebase --continue ``` ``` git mergetool ``` ``` git add <resolved-file> ``` ``` git rm <resolved-file> ``` # Undo ``` git reset --hard HEAD ``` ``` git checkout HEAD <file> ``` ``` git rm <resolved-file> ``` --- ## Adding a `.gitignore` file Make `.gitignore` file in the same directory as `.git` file. Open `.gitignore` file and add file names that you want git to ignore. `.gitignore` ``` settings.py *.pyc venv/ ``` --- # References * [GIT CHEAT SHEET](https://services.github.com/on-demand/downloads/github-git-cheat-sheet.pdf) * [GIT CHEAT SHEET by Tower](https://www.git-tower.com/blog/git-cheat-sheet)

COMMENTS







keep exploring!

back to all projects