This lists the steps to use Git for any Salesforce project considering below facts:
– GitLab is used
– VS code editor is used
To check changes if made locally
git status
- #If no repo
git init
- #If repo exist
- . Add only the files you want to push
#add core filesgit add sfdx-project.jsongit add config/git add manifest/ - # If you want to move all components
git add .# Only selected file to be pushedgit add force-app/main/default/classes/git add force-app/main/default/flows/git add force-app/main/default/objects/
- . Add only the files you want to push
- Local commit
git commit -m “Initial commit: Salesforce components” - Connect to GitLab and push
git remote add origin YOUR_GITLAB_URL_HERE
git branch -M main
git push -u origin main
- After first time, if you want to push further any subsequent change
git add .
git commit -m “describe what you changed”
git push
SOME IMPORTANT NOTES
- IF you have added wrong gitlab url then change as below:
git remote set-url origin https://gitlab.com/weeve2/weeve.git - If brnach is protected then
1. Go to your project >> Left sidebar → Settings →Click Repository → Protected branches - If you want to some file/folder not to be pushed then put it in gitignore
check if you are already logged in Gitlab in VS Code
git ls-remote https://gitlab.com/xx/yy.git
Otherwise login in gitlab
…..
In main repo, I want to delete all files as pushed some unwanted things
Run these commands to remove everything from remote (your local files stay untouched):
git rm -r --cached . git commit -m "Clear remote" git push origin main
This will leave the repo empty on GitLab. Then selectively add only what you want:
git add sfdx-project.json git add config/ git add force-app/ git add manifest/ git commit -m "Add Salesforce components" git push origin main
If need to delete a specific file/folder
git rm –cached .gitignore
git commit -m “Remove .gitignore from remote”
git push origin main
Manage Branches
Create and switch to a new branch
git checkout -b feature/package-xml
Add the package.xml
git add manifest/package.xml
Commit
git commit -m “Add package.xml”
Push to remote as a new branch
git push origin feature/package-xml