Hello World! Apart from adding, committing and pushing files to the repository, here are some common git operations, in a flash!
1. Branching
Branching is necessary when you want to work on a new feature (or for other reasons) and separate your code from master branch.
Create a branch and checkout:
git checkout -b nameOfYourNewBranch
Delete a local branch :
git branch -d branchName
Delete a remote branch:
git push origin -d branchName
2. Merging
Merging a branch is necessary because you might want to merge a feature branch to the master branch.
# Start a new feature
git checkout -b new-feature master
# Edit some files
git add <file>
git commit -m “Start a feature”
# Edit some files
git add <file>
git commit -m “Finish a feature”
# Merge in the new-feature branch
git checkout master
git merge new-feature
# Delete the new-feature branch
git branch -d new-feature
3. Stashing
Stashing is used when you temporarily want to put away your change and have the clean woking tree. Don’t worry, you will be able to get your stashed changes back.
Stashing current work:
git stash
Listing stashes
git stash list
Importing latest stash:
git stash pop
Importing particular stash if more than one:
git stash pop stash@{n}
Dropping stash:
git stash drop stash@{n}
Here, n refers to a number, 0, 1, 2… which represents which stash to delete.
4. Cleaning Cache
Cleaning cache is required when you want to remove previously added files which you don’t want to track anymore.
Clean all git cache:
git rm -r --cached .
Clean cache of only required file:
git rm fileName --cached
Top comments (0)