Git setup
Configuring the user information that will be utilized across all local repositories.
git config --global user.name “[firstname lastname]”
set the name that will be associated with your commits and tags.Example:
git config --global user.name “Indratej.dev”
git config --global user.email “[valid-email]”
set the email address that will be associated with your commits and tags.Example:
git config --global user.email "IndratejReddy@developer.com
git config --global color.ui auto
set automatic command line coloring for Git for easy reviewingExample:
git config --global color.ui auto
Start project
configuring user information, initializing and cloning repositories.
git init
create empty Git repo in specified directory. Run with no arguments to initialize an existing directory as a Git repositoryExample:
git init indratej_Devfile
git clone
clone repo located at onto local machine. Original repo can be located on the local filesystem or on a remote machine via HTTP or SSH.Example:
git clone https://github.com/techlifejournal/techlifejournal.git
git status
list which files are staged, unstaged, and untracked.
list new or modified files which are not yet committed.Example:
git clone https://github.com/techlifejournal/techlifejournal.git
git add [directory]
stage all changes in for the next commit. Replace with a to change a specific fileExample:
git add “Indratej.dev”
git reset [file]
unstage a file while retaining the changes in working directoryExample:
git reset [./yourfilename]
git diff
diff of what is changed but not stagedExample:
git diff
git diff --staged
diff of what is staged but not yet commitedExample:
git diff --staged
git commit -m “[descriptive message]”
- adds a descriptive message to your commits.*
Example:
git commit -m “[descriptive message]”
BRANCH & MERGE
isolating work in branches, changing context, and integrating changes.
git branch
list your branches. a will appear next to the currently active branch*Example:
git branch
git branch [branch-name]
create a new branch at the current commitExample:
git branch [branch-name]
git checkout
switch to another branch and check it out into your working directoryExample:
git checkout
git merge [branch]
merge the specified branch’s history into the current oneExample:
git merge [branch]
git log
show all commits in the current branch’s historyExample:
git log
INSPECT & COMPARE
Examining logs, diffs and object information.
git log
show the commit history for the currently active branchExample:
git log
git log branchB..branchA
show the commits on branchA that are not on branchBExample:
git log branchB..branchA
git show [SHA]
show any object in Git in human-readable formatExample:
git show [SHA]
SHARE & UPDATE
Retrieving updates from another repository and updating local repos
git remote add [alias] [url]
add a git URL as an aliasExample:
git remote add [alias] [url]
git fetch [alias]
fetch down all the branches from that Git remoteExample:
git fetch [alias]
git merge [alias]/[branch]
merge a remote branch into your current branch to bring it up to dateExample:
git merge [alias]/[branch]
git push [alias] [branch]
Transmit local branch commits to the remote repository branchExample:
git push [alias] [branch]
git pull
fetch and merge any commits from the tracking remote branchExample:
git pull
TRACKING PATH CHANGES
Versioning file removes and path changes
git rm [file]
delete the file from project and stage the removal for commitExample:
git rm [file]
git mv [existing-path] [new-path]
change an existing file path and stage the moveExample:
git mv [existing-path] [new-path]
git log --stat -M
show all commit logs with indication of any paths that movedExample:
git log --stat -M
REWRITE HISTORY
Rewriting branches, updating commits and clearing history
git rebase [branch]
apply any commits of current branch ahead of specified oneExample:
git rebase [branch]
git reset --hard [commit]
clear staging area, rewrite working tree from specified commitExample:
git reset --hard [commit]
IGNORING PATTERNS
Preventing unintentional staging or commiting of files
logs/ .notes pattern/
Save a file with desired paterns as .gitignore with either direct string matches or wildcard globs.Example:
logs/ *.notes pattern*/
git config --global core.excludesfile [file]
system wide ignore patern for all local repositoriesExample:
git config --global core.excludesfile [file]
TEMPORARY COMMITS
Temporarily store modified, tracked files in order to change branches
git stash
Save modified and staged changesExample:
git stash
git stash list
list stack-order of stashed file changesExample:
git stash list
git stash pop
write working from top of stash stackExample:
git stash pop
git stash drop
discard the changes from top of stash stackExample:
git stash drop