- Initialising a Repository
>> git init
- Adding changes to ready to commit state
# adding selected files
>> git add filename1 filename2
# adding all files
>> git add .
- Check status of Repository
>> git status
- Commiting Staged Changes
>> git commit -m "write your message here"
- Checking previous Commits
# show all the commits
>> git log
# shows specific number of commits with lesser details
>> git log --oneline -3
- Adding Author's details
>> git config --global user.name "name"
>> git config --global user.email "anyemail@gmail.com"
- Cherry-pick (moving one commit from another branch to current branch using COMMIT-ID)
>> git cherry-pick <COMMIT-ID>
- Creating a new branch
>> git branch <branchname>
- Show which is current branch
>> git branch
- Show all branches in the project
>> git branch -a
- Move to another branch
>> git checkout <branchname>
- Create new branch and move to it
>> git checkout -b <newbranchname>
- Deleting a branch locally
>> git branch -d <branchname>
# force delete
>> git branch -D <branchname>
- Renaming a branch
>> git branch -m <oldname> <newname>
- Creating a remote
>> git remote add <remotename> https://github.com/miPlodder/Project-Name-Link-From-Github
- Pushing changes to Remote
>> git push <remotename> <branchname>
- Pulling changes from Remote
>> git pull <remotename> <branchname>
- Force Push to Remote
>> git push -f <remotename> <branchname>
- Deleting a remote branch
>> git push <remotename> :<branchname>
- Delete last commit
>> git reset --hard HEAD~1
- Adding changes to last commit (instead of creating a new commit)
>> git add .
>> git commit --amend
- Deleting modified file changes
>> git reset --hard
- Deleting untracked files
# shows which untracked files are about to get deleted
>> git clean -n
# delete the untracked files
>> git clean -f
- Updating last commit message
# this will make changes on local repo
>> git commit --amend
# now if you want to make changes to your remote repo (force push)
>> git push -f origin master
* Command to squash last 'n' commits from HEAD
>> git rebase -i HEAD~3
>> git fetch <remote> <rbranch>:<lbranch>
>> git checkout <lbranch>
git revert --no-commit HEAD~n..
git commit -m "your message regarding reverting the multiple commits"
The ..
helps create a range. Meaning HEAD~3..
is the same as HEAD~3..HEAD