Git is a version control system which is used by most open source and collaborative programming projects. Below is a list of few very often used git commands. Hope its helpful.
1. Get the status of modified files
$ git status
2. Pull latest changes in current branch
$ git pull origin master
3. Switch to existing branch
$ git checkout branch-name
4. Checkout into your new branch
$ git checkout -b myNewBranch
5. Delete branch
$ git branch -D myLocalBranch
6. Show all branches, local and remote
$ git branch –a
7. Git reset/discard all changes until last commit
$ git reset –hard Or, $ git checkout -f $ git reset --hard origin/master
for moving to the head version
8. Applying the patch on current branch.
Note: You first need to check if patch has some conflicts. If there are no conflicts then only apply patch.
$ git apply --check ../DRILL-154.patch
$ git apply ../DRILL-154.patch
Verify if patch is applied:
$ git status
9. Add files to version control
Get list of files to be added to version control by ‘git status’ and then add the files one by one:
$ git add sandbox/web-frontend/drill.css
10. Finally commit files to branch
$ git commit -m "Your commit message here"
$ git commit -m “DRILL-154: Comment-Drill logo added in modal window”
11. Configure userid and email id for git commits (if not present in configs already)
$ git config --global user.name Yash
$ git config --global user.email email@example.com
$ git commit --amend --reset-author
12. To see commit histories
$ git log
13. To see details of particular commit (if you have the particular commit id)
$ git show 74a27b95ad83eb2eb69d76d17c97667ceac82283
14. Create patch from commit id
$ git show 74a27b95ad83eb2eb69d76d17c97667ceac82283 > DRILL-154.patch
Few Other Commands:
1. Pull with rebase: git pull –rebase
2. Create a patch with multiple commits(revisions) :
git diff HEAD~2..HEAD > patch.diff
3. Merge multiple commits into one: git rebase -i
Yash Sharma is a Big Data & Machine Learning Engineer, A newbie OpenSource contributor, Plays guitar and enjoys teaching as part time hobby.
Talk to Yash about Distributed Systems and Data platform designs.