Git Handbook
09/15/2018 Tags: GitPurpose
Due to the most of time on my job, I need to type many git command lines. So that this article is used to sort several git commands frequently used for easily searching.
Intorduction
Git is one of a distributed version control system (DVCS) commonly used for open source and commercial software development with significant benefit for individuals, teams and businesses. DVCS allows full access to every files, branches, and interation of project. Unlike once popular centralized version control system, such as perforce, DVCS don’t need a constant connection to a central repository. Developers can work anywhere and collaborate asynchronously from any time zone.
Basic Git Commands
Set your Name and Email in Git
Before working with Git on the command line, there are some basic configurations need to be set in advance.
By replacing {YOUR NAME} with your first and last name:
$ git config --global user.name {YOUR NAME}
Then, replaceing {EMAIL} with the email associated with your GitHub account:
$ git config --global user.email {EMAIL}
Now, you can see your current configurations, type:
$ git config --list
Connect a existing progect with github
If you have a existing progect and want to connect with github, you can do the following and start to tract with git.
# Initialize the local directory as a Git repository.
$ git init
# Add the URL for the remote repository where your local repository will be pushed.
$ git remote add origin < repository URL >
# Verifies the new remote URL
$ git remote -v
# Push an existing repository
$ git push -u origin master
High Frequency Git Commands
Table of Contents
- Show the status of the files on your branch
- Create a new branch
- Check out to your new branch
- Join two or more development histories together
- Compare the changes
- Add your file to the staging area
- See the histroy of commits
- Commit your file and type the commit message
- Push your commit to the remote and set a trackng branch
- Update your local copy of repository
- Stash your work
- Binary search the commit
Git Commands
- Show the status of the files on your branch:
- Create a new branch:
- Check out to your new branch:
- Join two or more development histories together:
- Compare the changes:
- Show you any uncommitted changes since the last commit, type:
- Compare a specific file across branches, type:
- Add your file to the staging area:
- See the histroy of commits:
- Commit your file and type the commit message:
- Push your commit to the remote and set a trackng branch:
- Update your local copy of repository:
- Stash your work:
- Stash uncommitted changes in local repo
- Re-apply your stashed changes
- Manage multiple stashes
- View stash diff
- Binary search to find the commit:
- Use binary search to find the commit
- Start a bisect session
- Bisect reset
- Bisect skip
- Show bisect log
$ git status
$ git branch {BRANCH-NAME}
$ git checkout {BRANCH-NAME}
$ git merge {BRANCH-NAME}
# First, let's check out to the "master" branch
$ git checkout master
# Then, merge Dev to current branch
$ git merge Dev
$ git diff
$ git diff {BRANCH-NAME} {OTHER-BRANCH-NAME} {FILE-NAME}
# Preparing to become part of the next commit
$ git add {FILE-NAME}
$ git log
$ git commit -m "your message"
$ git push -u origin {BRANCH-NAME}
$ git pull
$ git stash
# Reappling the changes and removing
$ git stash pop
# Reappling the changes and keeping
$ git stash apply
$ git stash list
$ git stash show -p
$ git bitsect <subcommand> <options>
$ git bitsect start
$ git bitsect reset
$ git bisect skip
$ git bisect log
# good: [72a35907200b42246fd039d495cbef8d80fdefe3] Miscellaneous
git bisect good 72a35907200b42246fd039d495cbef8d80fdefe3
# good: [72a35907200b42246fd039d495cbef8d80fdefe3] Miscellaneous
git bisect good 72a35907200b42246fd039d495cbef8d80fdefe3
# skip: [72a35907200b42246fd039d495cbef8d80fdefe3] Miscellaneous
git bisect skip 72a35907200b42246fd039d495cbef8d80fdefe3
# bad: [72a35907200b42246fd039d495cbef8d80fdefe3] Miscellaneous
git bisect bad 72a35907200b42246fd039d495cbef8d80fdefe3
Reference
[1] Git Handbook, GitHub Guides.
[2] Git stash
[3] Adding an existing project to GitHub using the command line
[4] Git bisect
Note
If you have any constructive criticism or advises, leave the comments below or feel free to email me @qazqazqaz850@gmail.com. Hope this post will help! :)