Author: alpha74
-
Working tree:
- All the physical files present in the project.
-
Staging Area:
- Place where changes to be included in next commit are stored.
-
Local Repository:
- Contains all the commits.
- A commit is snapshot of the project.
- Git uses Directed Acyclic Graph for storing commit history.
-
Remote Repository:
- Remotely located repository.
- Serves as global truth.
- Not has Staging Area and Working tree, only repo with commit hostory.
- It is often a "bare" repo. Names generally ends with
.git.
-
Terms:
HEAD: It points to last commit node on the branch. It is agit id. A Git Id is the name of Git object.
git --version: Tells version of git.
git init: Initializes the current directory into Git local repository.ls -la: Lists hidden files in the git repository.git init --bare: Creates remote repo.
-
git config --global user.name "<name>": To set the global user name -
git config --global user.email "<email address>": To set global email address. -
git config --list: Lists all configurations settings -
All flags:
-- system--local--global
git help <command>: Displays help menu. Displays large documentation.git <command> -h: Displays short description in cmd.
pwd: Current path of working directory.cd ~: Change directory to home(of bash).#: Used for comments.
git add .: Add all the changes in current dir to staging area.git add --a: Same as abovesgit add <file>: Makes changes made to that file ready for commiting.
touch <filename>: Creates new file.echo "<text>" >> <filename>: Store text in filename.git rm <filename>: Removes file(can only do after staging and commiting).
git status: Displays changes made to files in that directory which are/not yet commited.git status -s: Displays short oneline status of each file in staging area.
git commit -m "message": To commit with a message-mflag is optional, and is used for writing a short message with commit.
-
If no local repo exists:
git clone <link> [local repo name]:- To clone a git repository using link.
[local repo name]is optional.
git push -u origin <branch>:- Push commits to remote.
- Here, origin is an alias for URL of remote repo.
-
If local repo exists and some commits are in staging area:
git remote add origin <link of remote .git>: Add remote repo to local repo.git remote -vorgit remote --verbose: See details of remote repo.git push -u origin <branch>: Push commits to remote.-u: track this branch aka--set-upstream.- Here,
<branch>set up to track remote<branch>from origin.
-
git log: See all the commits. -
git log --oneline: Condensed version of log. -
git log --oneline -2: Will return only last two logs. -
git log --author="<user.name>": Lists all the commits done by a specific user. -
git log <git id> -1: See one liner log associated with given commit hash.git idis 4 or more chars of hash value of commit. -
git show <git id>: Shows detailed changes associated with this commit along with author and differences. -
Graphs:
git log --oneline --graph: Graphical view of commits on local branch with comparison.