This Repository contains about git commands and the explanation for each command along with the different flags each command takes
> git config --global user.name "user name"
> git config --global user.email "emailId"
> git config --global core.editor "code --wait" waits for window
*** By defualt it uses vim ***
-Apply the shell command in vscode. This allows Git to know who is code
*** search ">code" -> Install 'code' command in path ***
> git config --global init.defaultBranch 'master' (can also be main)
> git config --global core.autocrlf input // Use true on Windows
To Check settings:
1. git config --global -e
2. In root: .gitconfig File
git config --global alias.<shortcut> <command>
Example : alias.st status
git config --global credential.helper store
- Staging Area/Index
- Temporary space b/w working directory and the project history
- The file to be committed are put here.
- This allows to group files going into next commit(snapshot)
- git ls-files: Shows the files in Staging Area
- Used for setting Options
- FLAGS
- --system : For all the users in the system
- --global : For all the repositories of THAT user
- --local : For a single repository
- Creates a copy of the Remote Existing Repository
- usage: git clone
URL - A new folder with the same name as Repo is Created
- Moves files into staging Area
- This makes git to start tracking the file
- Use this command as soon as (part of) work on file is DONE
- Usage: git add filename1
- To untrack: git rm --cached filename1
- FLAGS
- Tracks all files: --all / -A:
- to UNSTAGE files
- git restore --staged filename1 ...
- Gets the INFO from REMOTE to the LOCAL repo
- DOESNT UPDATE THE WORKING AREA yet
- Update the local repo with the Remote Repository
- Brings the changes DIRECTLY to WORKING AREA!
- helps stay in the latest version of the Repo
- In essence :
PULL = FETCH + MERGE
- Save a snapshot of the files staged
- Opens the COMMIT_EDITMSG file in the .git Folder in the preferred Editor
- FLAGS
- -m: Commit message directly as cmd argument
- -am: Add all files and commit them
- The -am option
cannot be usedon files newly created. - It is used for files added earlier but
further changes mademust be added and committed simultaneously! - So for a NEW FILE, first use
git addONLY
- The -am option
- Shows the full status of the local directory (working tree information)
- FLAGS
- -s: short style status info
- Shows difference b/w files Unstaged and Last Commit
- FLAGS
- --staged/cached: Shows difference b/w files Staged and Last Commit
- git diff
branch1..branch2OR git diff branch1 branch2 (Both produce same results) - git diff
commit_id-1..commit_id-2OR git diff commit_id-1 commit_id-2
- Example of git diff

- Note that --- and +++ doesnt mean Addition or deletion from file. In git diff, it actually denotes the
Block of code from the respective files - For example: -Trying the fast forward merge is the block from file a/ffw1
- Push the commited code to the remote Repo
- Requests for Username and PAT (Personal Authentication Token)
- Example snip of a git push

- We can also use SSH keys
- FLAGS
- -u remote-name local-branch-name : Sets an upstream by linking the remote and local branch. This allows git push to understand where to push in the FUTURE
-
Shows the previous commited versions of the Repository
-
Includes Author,Date, Commit-id
-
FLAGS
-
SUBCOMMAND
- git log $branch-name : Shows log of that particular branch
-
Shows where the HEAD is pointing
-
This HEAD can be seen inside .git folder
- Creates a new timeline from the current Branch
- Deletes the specified Branch
-
Example branching condition
- Renames the current branch name to the specified name
- Moves the HEAD to branch-name mentioned
- Alias to checkout is
switch - FLAGS
- git switch -c new-branch
Creates the branch and Switches - git checkout -b new-branch
Same as above - git checkout $HASH-ID
Detaches HEAD. To re-attach use git checkout main - git checkout HEAD~2
**Moves two COMMITSBehind
- git switch -c new-branch
- SUBCOMMAND
- git checkout $hashid
- git checkout $hashid
- ** commit before switching a branch
- Three types of Merge exists
- Fast forward merge
- This is where the master does no commit
- The branch has CHANGES
- Since the Master Didnt move at all, We fast forward Master to the new HEAD
- Not a fast forward
- The master and branch have done some commits of their own
- But the commits dont conflict (Not of SAME FILE)
- Conflict Merge
- Fast forward merge
-
Lets say we create a main repo, work and commit some changes
-
Now switch to another branch and work such that there is
conflicting changes -
Now without
committing(even adding the file won't suffice), wecannot checkoutto another branch -
During this case, we use STASH. This locally saves the changes
-
SUBCOMMANDS
-
NOTE: git stash pop can be POPPED into
ANY OTHER BRANCH. From BRANCH-1 I can stash and Pop it into BRANCH-2!!!
- Used to restore a file to its previous state
NEVER RUN THIS FROM THE MAIN BRANCH
- It is a MERGE command, only that the branch is fully detached and planted to MASTER
- This eliminates unnecessary messages like Merge branch to master
- Conflicts occur and must be resolved like in MERGE COMMAND
- After resolving conflict, must
ADD the filethen dogit rebase --continue
- After resolving conflict, must
- MERGES into
SINGLE TIMELINE 
- Prints the tags assigned for particular commit-ids
- Useful when versioning the code. Makes it easier to go back to prev versions using a TAG
- TAG is better to use than HASH-ID
- USAGE :
- git tag "tag_name"
(DOESN'T ALLOW SPACES)Tags the Current Branch - git tag "tag_name" $HASH-ID
- git tag "tag_name" HEAD~2
- git tag "tag_name"
- EXAMPLE

- Similar to MERGE and REBASE
- Rather than merging the ENTIRE COMMIT TIMELINE, picks commits which should MERGE
- USAGE: git cherry-pick $hash-id-1 $hash-id-2 ...
(ORDER MATTERS) - Creates new commits on the current branch for the
INCOMING COMMITS. 
- Each commit create a complete snapshot of the project
- Uses compression to save space
- Doesn't allow duplicates
- Note that it doesnt store the delta change
- It also stores ID, Author, Date/time, Message
- When a file is already added (v1), then modified(v2), Git shows it as untracked
- But the prev version added is still tracked
- now if we commit and push, v1 is pushed. v2 is still untracked!
- only in the next commit can we push v2
- When doing rm filename, This change is not staged
- Thus we need to ADD the file, and commit
- If we want to remove File from working dir AND staging area
git rm filenames
- Like removing a file, use the command
git mv filenames
- Does the staging of new file and deleting of old file
- Create a file named .gitignore
- File: test.txt
- Directory: dir1/ **remember to use fwd-slash
- Look for gitignore generator. Has templates for different programming languages
- First Parent points to NULL
- The Child version's Hash is generated using the Parent's information



