Command | Description |
---|---|
git init |
Create a git repository rooted at the current directory. The repositor's contents
are stored in a hidden |
git status |
displays any files or folders that have been created, modified, or deleted |
git add -A |
stages all changes for commit |
git commit -m"message" |
Captures a snapshot of all the current files in the working directory tree. |
git commit -m"message" -- <file1>, .. |
Captures a snapshot of one or more specific files in the working directory tree. |
git branch <name> |
Creates a branch site at the commit pointed to by Head. |
git checkout branchname |
Switches to the named branch, changing all code in the working tree to match the latest commit on that branch. This process is reversible. Before checkout commit to a clean working tree. |
git log [--graph | --oneline] |
Display all commits. The option --oneline provides a compact display with less
information. Option --graph shows a compressed graph with separate branches.
To view all relevant details use |
git reflog |
Display commits, checkouts, resets, ... |
git reset [--soft | --hard] <commit id> |
Moves Head backward in history to the named commit. That changes code in the directory tree to that of the named commit. The --soft option makes the original Head code unstaged, so that can be added and committed. The result is removing the intervening commits. The --hard option permanently deletes all additions, modifications, and deletions after the target commit. |
git diff <src branch> <tgt branch> |
Displays differences between code in those branches. Use this to set code for successful merges. |
git merge <src bran> <tgt bran> |
Attempts to merge code from the two branches. This may fail. If you committed
both branches to a clean state before merging, then the command "git reset --merge" will
return to the pre-merge state.
References:
How does git merge work? |
git remote add <name> <url> |
Establishes connection string for push and pull commands. |
git push <remote name> <branch name> |
Pushes local changes to remote repository. |
git pull <remote name> <branch name> |
Pulls changes from remote repository. |