Main Repo (Upstream)
Fork Repo (Fork)
main <- fork
- Clone Remote repo on local machine
git clone [repo url]
- Add remote repo url
git remote set-url origin [repo url]
- Add commit
git add . git add [filename] git commit -m "Message"
- Push branch and branch changes to remote
git push origin [branch_name]
- Update local branch/ take main branch changes
git pull origin [branch_name]
- Fetch particular branch locally (branch should be on remote)
git fetch [branch_name]
- Fetch all remote branches locally
git fetch --all
- Create new branch from updated local branch
git checkout -b [new branch name]
- Delete local branch (current branch should not be the same branch)
git branch -D [branch name]
- Cherry pick (copy br_A commit to br_B)
git cherry-pick [commit id]
- Merge remote/locally branch locally
git merge [branch name]
- Revert modified/tracked file (file exist on remote but made changes on local and have to revert changes)
git revert --stage [filename]
- Revert new/Untrack file (new file)
git clean -fd
- Resolve conflicts scenario
git commit (commit local changes) git pull (pull remote changes) resolve conflicts in local branch git add . (add resovled conflict files) git commit git push (push to remote branch)
- Update last commit A.
git add [file_name] / git add . git commit --amend git push -f origin [branch name]
16 Switch branch
git checkout [branch name]
- Set(restore) head to specific commit
git checkout [commit id]
- Commit history
git log
- Current branch status
git status
- List All visible branches
git branch
- List all(visible + hidden) local branches
git branch -a
- Current remote url
git remote -v
- Initialize current directory with git
git init
- Adding author name
global: git config --global user.name "Nitin Kadam" local: git config user.name "Nitin Kadam"
- Adding author email
global: git config --global user.email "[email protected]" local: git config user.email "[email protected]"
- Check file history
git blame [filename]