Using Git Pull and Push with Shallow Clones | Generated by AI

Home PDF

Yes, you can still use git pull or git push after cloning a repository with a limited history using --depth=20. However, there are some important considerations to keep in mind:

1. What --depth=20 Does

2. Using git pull with a Shallow Clone

Note: If the branch’s history changes in a way that affects commits older than your shallow history (e.g., a force push or rebase on the remote), you may encounter issues. In such cases, you might need to deepen the history (using git fetch --deepen=<n> or git fetch --unshallow to fetch the full history) to resolve conflicts or continue working.

3. Using git push with a Shallow Clone

4. Limitations of Shallow Clones

5. How to Deepen a Shallow Clone (If Needed)

If you encounter issues with git pull or git push due to limited history, you can fetch additional history:

6. Practical Advice

Example Workflow

# Clone with limited history
git clone git@github.com:cisco/ChezScheme.git --depth=20
cd ChezScheme

# Make changes and commit
git commit -m "My changes"

# Pull latest changes
git pull origin main

# Push your changes
git push origin main

If you run into issues due to the shallow clone, deepen the history as described above.

Summary

Yes, you can use git pull and git push with a shallow clone created using --depth=20. However, you may need to fetch additional history for certain operations if the shallow history is insufficient. Use git fetch --deepen or git fetch --unshallow to address any limitations.


Back 2025.06.26 Donate