Basic GIT Commands
Here is a list of some basic Git commands to get you going with Git.
Create a new local repository
git init
Check out a repository
git clone <repository_host>
Add Files
git add <filename>, git add *
If you mess up, you can replace the changes in your working tree with the last content in head:Changes already added to the index, as well as new files, will be kept.
git checkout -- <filename>
Commit changes to head (but not to the remote repository)
git commit -m “Commit message”
Commit any files you’ve added with git add, and also commit any files you’ve changed since then
git commit -a
Send changes to the master branch of your remote repository
git push origin master
List the files you’ve changed and those you still need to add or commit
git status
Displays the differences between versions and merge conflicts
git diff
Connect to a remote repository
git remote add origin <server>
List all currently configured remote repositories
git remote -v
Search the working directory for foo()
:
git grep "foo()"
Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this:
git fetch origin
git reset --hard origin/master