GIT commands
Git command Flow:
Setup:
git config --global user.name “[firstname
lastname]” |
set a name that is identifiable for credit when review
version history |
git config --global user.email “[valid-email]” |
set an email address that will be associated with each
history marker |
|
Git has a
limit of 4096 characters for a filename, except on Windows when Git is
compiled with msys. It uses an older version of the Windows API and there's a
limit of 260 characters for a filename. So as far as I understand this, it's a limitation of msys and
not of Git. You can read the details here: https://github.com/msysgit/git/pull/110 |
Setup & Init:
git init |
Initialize an existing directory as a Git repository |
git clone <repository_url> |
retrieve an entire repository from a hosted location via
URL |
|
fetching all the branches and checking out one |
|
Prevent fetching of all branches |
Stage & Snapshot:
git status |
Show modified files / Staged for next commit |
|
add a file as it looks now to your next commit (stage) |
git reset [file] |
unstage a file while retaining the changes in working
directory |
git diff |
diff of what is changed but not staged |
git diff --staged |
diff of what is staged but not yet committed |
git commit -m “[descriptive message]” |
commit your staged content as a new commit snapshot |
Branch & Merge:
|
List all branches |
git branch [branch-name] |
create a new branch at the current commit |
|
Checkout the branch |
git merge [branch] |
merge the specified branch’s history into the current one |
git log |
show all commits in the current branch’s history |
git log branchB..branchA |
show the commits on branchA that are not on branchB |
git diff branchB...branchA |
show the diff of what is in branchA that is not in branchB |
Share & Update:
git remote add [alias] [url] |
add a git URL as an alias |
git fetch [alias] |
fetch down all the branches from that Git remote |
git merge [alias]/[branch] |
merge a remote branch into your current branch to bring it
up to date |
git push [alias] [branch] |
Transmit local branch commits to the remote repository
branch |
git pull git pull origin [branch] |
fetch and merge any commits from the tracking remote
branch |
Rewrite History:
git rebase [branch] |
apply any commits of current branch ahead of specified one |
git reset --hard [commit] |
clear staging area, rewrite working tree from specified
commit |
Temporary commits:
git stash |
Save modified and staged changes |
git stash list |
list stack-order of stashed file changes |
git stash pop |
write working from top of stash stack |
git stash drop |
discard the changes from top of stash stack |
Important links:
https://medium.com/javarevisited/git-commands-that-you-must-know-7ff17fab7482
Comments
Post a Comment