## Initial Setup ### git init Create an empty git repo or reinitialize an existing one [git-init manual](https://www.kernel.org/pub/software/scm/git/docs/git-init.html) ### git clone ```shell $ git clone https://github.com/jedhunsaker/codepainter.git codepainter ``` Clone a repo into a new directory [git-clone manual](https://www.kernel.org/pub/software/scm/git/docs/git-clone.html) ### Checkout a remote branch with tracking. `git checkout --track -b origin/` -B to force it. ### Checkout fork's master branch with upstream/master as remote. `git checkout -b master upstream/master` ### Push a local branch for the first time. `git push --set-upstream origin `
`git push` ### Push a local branch to a different remote branch. `git push origin :` -f to force it. ### Squash a number of commits into a single commit. `git rebase -i HEAD~` ### Commit all changes with a message. `git commit -am ` ### Remove a local branch. `git branch -d ` -D to force it. ### Remove a remote branch. `git push origin :` ### Manually set tracking. `git config branch..remote origin`
`git config branch..merge refs/heads/` ### Do a pull, stacking your recent commits on TOP of the pulled commits. `git pull --rebase` ### Undo last push `git reset --hard HEAD~1 && git push -f origin master` ### Rebase on upstream master `git fetch upstream && git rebase upstream/master` ### List the set of repositories ("remotes") whose branches you track. `git remote -v` ### Checkout as CRLF, Commit as LF `git config --global core.autocrlf true`