Git task Notes Git commands
Tell Git who you are Configure the author name and email address to be used with your commits
git config --global "Sam Smith"
git config --global ""

Create a new local repository

After executing the command the current folder will be git repository
git init

Clone a repository

Clone command will copy the source repository to the current folder. The original repository is typically located on remote machine, but it can be located also ont the local filesystem
git clone <source repository>

Stage files

Add one or more files to staging
.(dot) means all files in current directory
git add <filename>
git add .


Commit changes to head (but not yet to the remote repository):
git commit -m "Commit message"


Send changes to the master branch of your remote repository:
git push origin master

Force Push

Sometimes git does not allow you to push to remote branch. (Example if the local branch is behind the remote branch). If you still want to push, you can use force push:
git push origin master --force
Status List the files you've changed and those you still need to add or commit:
git status

Connect to a remote repository

If you haven't connected your local repository to a remote server, add the server to be able to push to it:

git remote add origin <server>
List all currently configured remote repositories:
git remote -v


Create a new branch and switch to it:
git checkout -b <branchname>
Switch from one branch to another (existing branch):
git checkout <branchname>
List all the branches in your repo, and also tell you what branch you're currently in:
git branch
Delete a branch:
git branch -d <branchname>
Push the branch to your remote repository, so others can use it:
git push origin <branchname>
Push all branches to your remote repository (named origin):
git push --all origin

Update your current local working branch

Fetch and merge changes from the remote server to your working directory:
git pull
To merge a different branch into your active branch:
git merge <branchname>

View all the merge conflicts:

View the conflicts against the base file:

Preview changes, before merging:

git diff

git diff --base <filename>

git diff <sourcebranch> <targetbranch>
After you have manually resolved any conflicts, you mark the changed file:
git add <filename>


CommitId is the leading characters of the changeset ID.
You can get a list of the CommitId's
git log
If you want to see also commits after reset:
git log -g


You can use tagging to mark a significant changeset, such as a release:
git tag 1.0.0 <commitID>
Push all tags to remote repository:
git push --tags origin


You can reset your repo to the stage of tag
git reset --hard 1.0.0
And you can also reset your repo to the stage of some commit
git reset --hard commitID
You can find more instructions about git from

Toggle Menu