Git and GitHub for Salesforce

Git is an extremely popular version control system (VCS) which is installed on your local system. GitHub is an online database that allows you to keep track of and share your Git version control projects outside of your local computer/server. Unlike Git, GitHub is exclusively cloud-based.

Git Commands:

  • git –version
  • git config –global user.name “Your Name” – Set your name to associate as the author of future Git commits. This should be your first and/or last name.
  • git config –global user.email “you@email.com” – Set your email address to associate as the author of future Git commits. This should be the email address you use with GitHub.
  • git init – To initialize and start tracking your project files.
  • git log – log/history.
  • git add . – To stage all changes.
  • git commit -m “first commit”.
  • git branch -M main
  • git remote add origin https://github.com/yourgitname/projectrepositoryname.git – to connect your local project folder to the remote git project repository.
  • git push -u origin master
  • git remote -v – to check remote repository url.
  • git status
  • git push –set-upstream origin master or use the shorter version: git push -u origin master – To push the current branch and set the remote as upstream.
  • git checkout -b feature-branch –  Switch to a new Git branch named feature-branch. Or use git checkout master – to change to the master branch.
  • git pull origin master – Pull to your local project folder after you have merged all your feature branches to master.

Merge conflicts can occur when people make different changes to the same line of the same file.

To test the merged code before deploying it to your Dev Hub org, then you can create a new scratch org or sandbox to be your QA environment.

Check out these recourses: