git init
This will initialize a local repository in the directory that the command was executed in. Upon completing the command, git adds a hidden folder called .git that stores everything from change sets, branches and more. Deleting the folder deletes the local repository.
git status
This will look at all of the files in the local repository and determine which files are untracked, which files are added to the repository, and which files are committed.
git add {file_name_1} {file_name_2} ...
This will add the specified files to an Initial Commit where they will be ready to be committed to the repository. This stages the file(s) at their current state. If the files are modified, then only the first modification of the files would be committed. Run the command again to stage their latest changes.
use git add * to add everything.
git reset {file_name_1} {file_name_2} ...
This will undo anything that was added for a commit. Use git reset to un-stage all files.
git commit -m "Message"
This will commit all of the additions/modifications that were staged for commit. The -m specifies a message for the commit that is supposed to indicate what was changed to the repository. This will show up in remote repositories as well.
Adding -a will skip the staging process, meaning any files that are tracked will be automatically staged, however, any new files that are untracked will have to be added manually using git add.
git branch {branch_name}
This will create a new branch off of the master branch.
To delete a branch:
git branch -d {branch_name}
Note that this will only work if the branch has already been fully merged in its upstream branch. Otherwise, you can use -D to force delete it.
git checkout {branch_name}
This will switch your following git functions to only apply to the new current branch.
git merge {source_branch}
Ensure that you are on the Destination Branch before you do this. This will merge all of the changes from the specified source branch into the current destination branch.
git stash
When you want to save your changes without committing them, you can use stash to save tracked modifications on a stack of unfinished changes that can be reapplied at any time. This allows you to continue to use git commands without interfering with any files in the stash. Note that the modifications must be tracked, so you must do a git add on any files that you wish to be stashed before running the command.
To reapply the changes onto your branch:
git stash apply
This will reapply the modifications into the staging process so that they are ready to be committed.
To list all of the available remote repositories:
git remote
If you have connected to any remote repositories, this will list them out. Use -v to list all of the URL’s for them as well.
To add a remote repository available to your local repository:
git remote add origin {url}
To remove remove the remote repository: git remote remove origin.
git clone {url}
This will pull all of the files from a remote repository into the current directory. It pulls the project in its entirety including its git history.
git fetch origin {branch}
This will pull any changes made to the remote repository since the time it was cloned to your computer. If you add a branch name to the end, it will only fetch the changes from that branch. You will have to use git merge to merge the changes into your local repository.
git pull origin {branch}
This works the same as git fetch, but will also merge all of the changes in your local repository. If you add a branch name to the end, it will only fetch and merge the changes from that branch.
git push origin {branch}
This pushes all of the changes in your local repository to the remote repository and commit them to the specified branch.