Your cart is currently empty!
Cloning Large Repos and Working with Shallow Clones
- Shallow Clone:
git clone --depth=1 <repo-url>to download just the latest commit. - Unshallow: To fetch the rest of the history after shallow cloning, use
git fetch --unshallow.
Fetch, Merge, and Pull
- Fetch updates without merging:
git fetch origin master - Merge changes from
origin/masterinto the current branch:git merge origin/master - Pull changes (fetch + merge in one step):
git pull origin master
Commit Management
- Change the most recent commit message:
git commit --amend - Push commits and tags to
origin:git push origin mastergit push origin master --tags
Inspecting and Resetting Files
- List tracked files:
git ls-files - Unstage a file:
git reset HEAD <filename> - Reset changes to a file:
git checkout <filename>
Logs and History
- Graphical commit log:
git log --graph --oneline --decorate --all - Follow file history, including renames:
git log --follow <filename> - See reflog (checkout, commit, pull history):
git reflog
Merging and Rebasing
- Merge a branch without fast-forwarding:
git merge branchname --no-ff - Rebase a branch onto another:
git rebase master - Abort or continue a rebase:
git rebase --abortgit rebase --continue
Stashing Changes
- Save changes to stash:
git stash save "message" - Apply a specific stash:
git stash apply stash@{1} - Stash both tracked and untracked files:
git stash -u
Tagging
- Create a simple tag:
git tag myTag - Create an annotated tag:
git tag -a ver1.0 - Delete a tag:
git tag -d myTag
Cherry Picking
- Apply a specific commit from another branch:
git cherry-pick <commitID>
Branch Management
- Delete a branch:
git branch -d branchName - Create a new branch from another branch:
git branch newBranch origin/otherBranch - Set a branch to track another remote branch:
git branch --set-upstream-to=<remote/branch>
Dealing with Merge Conflicts
After a conflict arises, resolve it by editing files, staging the changes, and committing the merge: