After installing GIT on your local machine, you should set up your identity (global not per repository):
git config --global user.name "Your Name"
to check your identity setting use:
git config user.name
git config user.email
To create new Local repository :
git init
which will create git repository in the current directory, or
git init <project directory>
which will create git repository in the requested directory.
At any time to see the current state of repository use:
git status
Now we need to add all the existing code in the directory to the newly created repository:
git add *
or
git add file1 file2 file3
to see what is in the staging area (about to be committed)
git diff --cached
or as discussed above
git status
Which moves the code to the staging area (where we group items we want to commit). To commit those items:
git commit -m “commit message”
you can again check the status of the repository with
git status
also, a useful command that shows the committed changes is:
git log
To see history of specific file
git log file1
To see a graph representation of data
git log --graph --decorate --oneline
To check out code from remote location to your local repository:
git clone URL
Or
git clone username@host:URL
To pull changes from remote repository to your local:
git pull
to push your local repository to master (remote)
git push origin master
to list branches:
git branch
to create new branch and switch to it
git checkout -b branchname
to switch to another branch
git checkout branchname