Create empty repository:
$ssh user@host git init --bare /path/to/repo.git
Clone:
$git clone ssh://user@host/path/to/repo.git
Reset:
Remove the file from staging
$git reset [file_name]
To reset the staging are just use the below command
$git reset
Status:
shows the files Changes to be committed, Changes not staged for commit, Untracked files
$git status
This allows previewing a commit to be made.
Add:
$git add -A //stage all ( new, modified, deleted) files
$git add . //stage all ( new, modified, deleted) files
$git add --ignore-removal . //stage new and modified files only
$git add -u //stage modified and deleted files only
Diff:
Shows the changes between the working directory and the index. This shows what has been changed, but is not staged for a commit.
$git diff
Shows the changes between the index and the HEAD (which is the last commit on this branch). This shows what has been added to the index and staged for a commit.
$git diff --cached
Shows all the changes between the working directory and HEAD (which includes changes in the index). This shows all the changes since the last commit, whether or not they have been staged for commit or not.
$git diff HEAD
This shows the list of files what have been added to the index and staged for a commit.
$git diff --cached --name-only
Note: use --name-only options with diff if you just want to see files name.
Modify commit message:
amend staged commit statement
$git commit --amend -m "i missed mentioning these changes ...."
Branch:
Create new branch
$git checkout -b [branch-name] master // -b option tells to create a new branch.
push to remote
git push -u origin [branch-name]
Using git branch -r lists all remote branches and git branch -a lists all branches on local and remote. These lists get outdated though. To keep these lists up-to-date, run
$git remote update --prune
which will update your local branch list with all new ones from the remote and remove any that are no longer there. Running this update command without the --prune will retrieve new branches but not delete ones no longer on the remote.
You can speed up this update by specifying a remote, otherwise it will pull updates from all remotes you have added, like so
$git remote update --prune origin
List all remote branch
$git branch -r
remote show shows all the branches on the remote, including those that are not tracked locally and even those that have not yet been fetched.
$git remote show origin
Rename Branches:
Rename your local branch.
If you are on the branch you want to rename:
$git branch -m new-name
If you are on a different branch:
$git branch -m old-name new-name
Delete the old-name remote branch and push the new-name local branch.
$git push origin :old-name new-name
Reset the upstream branch for the new-name local branch.
Switch to the branch and then:
$git push origin -u new-name
Rebase:
$git pull --rebase origin master
Git log:
$git log --graph --all --oneline
$git log master..branch-X # That will show you commits that branch-X has but master doesn't
$git log --oneline --decorate
Revert by commit number:
$git revert -m 1 [commit-hash]
Merge:
$git checkout feature
$git merge master
Remove from staging:
$git restore --staged .
$
git restore --staged <individual_file>