Using pull, commit, and push- the 3 most important git commands

There are 3 things that we must do to keep the integrity of our repository on the project we’re working on. These steps will help us avoid complications such as merge conflicts like changes made on the github repository that has not been made on the local machine repository.

First, we want to pull from the server. If members on your team added new changes to the github repository, pulling those changes from the server will add the new changes to your local repository. When you add new changes from your local repository to the github repository, this will keep the project in sync avoiding conflicts that will force you to go back and pull those new changes to your local machine. Then afterward you can add the new changes you made to the github repository. The command to use is as follows:

  • git pull origin master - origin is the github server, and master is the branch you’re merging with.

Second, we will commit all new changes made on our local machine. To do this you must add all new files that have changes. The files that need to be committed will be in red.

To add these files, you have 2 options to choose from:

  • Use (git add “filename in red as shown”)
  • Or (git add .), the period will add all files that have changes in them.

Third, we must commit our file changes to save them to our local repository. Before we do that, one thing we must keep in mind is that if our file changes are too large, we must use LFS to commit and push these changes. LFS which stands for Large File Storage, stores references to the file in the repository up to 2GB. To install LFS, go to its website git-lfs.github.com, click download, and run the setup wizard. Inside git bash you will run the following command:

  • git lfs install- which should give you “<Git LFS Initialized” to show successful installation. You can only install once per account.
  • Change your current working directory to the existing repository you’d like to use with Git LFS.
  • Select the file types you like GIT LFS to manage (git lfs track “*. extension filename”). Example- git lfs track “*.cs”

Make sure to use “git status” to check if it went through. Then you must add the change again if it’s in red using “git add”. Finally, make sure .gitattributes is tracked (git add .gitattributes). It’s recommended you commit your local .gitattributes file into your repository, because relying on a global .gitattributes file associated with Git LFS may cause conflicts when collaborating with other Git projects.

Fourth, we can now commit our changes, which means we’re saving our changes to our local repository. The command we use is as follows:

  • git commit -m “description of what changes were made” in quotations.

Last, push all our changes to the Github server by using the following command:

  • git push origin master (you’re pushing to the github server in the master branch)

Next, we will get into working with branches.

Learning to become a Unity game developer.