CREATE A REPOSITORY | |
---|---|
git init [project name] | Create a new local repository |
git clone my_url | Download from an existing repository |
Git/GitHub
GitHub is a hosting platform for source code and files with version control using Git. It enables developers and any registered user to contribute to private and/or open source projects from anywhere in the world.
OBSERVE YOUR REPOSITORY | |
---|---|
git status | List new or modified files not yet committed |
git diff | Changes not staged |
git diff --cached | Changes staged for commit |
git diff HEAD | All changes (staged + unstaged) |
git diff commit1 commit2 | Diff between two commits |
git blame [file] | Line change authors |
git show [commit]:[file] | File contents at commit |
git log | Full change history |
git log -p [path] | History with patches |
WORKING WITH BRANCHES | |
---|---|
git branch | List local branches |
git branch -av | List all (local+remote) branches |
git checkout my_branch | Switch branch |
git branch new_branch | Create branch |
git branch -d new_branch | Delete branch |
git checkout branch_b | Prepare merge into branch_b |
git merge branch_a | Merge branch_a into current |
git tag my_tag | Create lightweight tag |
MAKE A CHANGE | |
---|---|
git add [file] | Stage file |
git add . | Stage all changes |
git commit -am 'message' | Commit tracked changes |
git reset [file] | Unstage file (keep changes) |
git reset --hard | Discard all local changes |
git commit -m 'message' | Commit staged changes |
SYNCHRONIZE | |
---|---|
git fetch | Update remote refs (no merge) |
git pull | Fetch then merge |
git pull --rebase | Fetch then rebase |
git push | Push current branch |