Add a remote
git remote add origin https://github.com/user/repo.git
See Adding a remote – GitHub Help
Create and checkout a new branch
git checkout -b [branchname]
example;
git checkout -b master
Checkout a remote branch
git checkout -b [localbranchname] origin/[remotebranchname]
example;
git checkout -b master origin/master
Delete a local branch
git branch -D [branchname]
example;
git branch -D BranchName
Delete a remote branch
git push origin --delete [branchname]
example;
git push origin --delete BranchName
Automatically stage tracked files
git add -u
Automatically stage tracked files in a folder
git add -u folder_name
example;
git add -u myfoldername
Commit
git commit -m {commit message}
example;
git commit -m "Update WordPress to version 4.3"
Get a list of all changed files after most recent pull.
git diff --name-status ORIG_HEAD..
Stash Changes
If you wish to switch branches, but don’t want to commit what you’ve been working on yet you’ll need to stash your changes.
git stash
To see which stashes you’ve stored, you can use git stash list:
git stash list
If want to keep your local modifications, use stash to hide them away before pulling. Then apply them afterwards.
git stash
git pull
git stash pop
Discard all local changes
If you’ve changed files, but wish to revert back to the last committed version.
git checkout -- .
Remove untracked files
git clean -f
Dry Run:
git clean -f -n
Remove ignored files
git clean -f -X
Remove directories and files
git clean -f -d
Update Git to use new .gitignore file
Commit all outstanding code changes before running the below commands.
Remove everything from the index;
git rm -r --cached .
Then run;
git add .
Commit it;
git commit -m ".gitignore is now working"
Solution courtesy of.gitignore file not ignoring – Stackoverflow
Tip. Using Coda 2’s built-in Git tools? After running the above commands close and restart Coda 2.
Edit/Amend last commit message
git commit --amend -m "New commit message"
Ignore permissions on working directory
git config core.filemode false
Ignore symlinks
Add all symbolic links to your .gitignore
find . -type l >> .gitignore
Remove all symbolic links from repository
find . -type l -exec git rm --cached {} \;
Ignore File Permission Changes
Make Git ignore local file permission changes.
Change to .git directory
Run:
git config core.fileMode false