-
Notifications
You must be signed in to change notification settings - Fork 10
Git Crash Course
Git is a code version control tool that allows us to collaborate on code together in a seamless and safe way. Git can be visualized as a working tree, where the main branch is the trunk and there are other smaller branches that come in and out of the trunk. This wiki will illustrate several commands and practices that may be used by developers in our workflow. There are many ways to do the same task with git, for instance, one may be able to merge with a command in the terminal locally, through the UI on the repository website, or through VSCode. We will illustrate just a few ways to help get you started with the basic commands.
Initialize a repository with your desired project name:
git init [project-name]
Copy a repository, either locally or from a remote server:
# from a remote server
git clone username@host:/path/to/repository
# from a local directory
git clone /path/to/repository
Adding files for staging, done before committing:
# Add one file or directory
git add [file-name]
# Add all changes in the directory
git add .
# Add all changes in the repository
git add -A
Commit the staged files:
git commit -m "Insert your commit message here"
Check your git status, displaying the list of changed files together with the files that are yet to be staged or committed.:
git status
Check your current branch:
git branch
Switch to a new branch:
git checkout [branch-name]
Create a new branch off the branch you are currently on:
git checkout -b [new-branch-name]
Updating your local repository from the remote one:
git pull
Merging a local branch into the local active one.:
git merge [branch-name]
Pushing to the remote origin:
# To push an existing branch
git push
# To push to a new branch that does not exist remotely
git push -u origin [new-branch-name]
If you are trying to initialize a new repository, using our expo template.
# Initialize a repository in your desired local directory
expo init --template maet-expo-template
# Go to github.com and create a repository on the web portal.
# Do not initialize the repository with a README and copy their commands to initialize a repository from the command line.
# These commands will look something like the following:
git remote add origin username@host:/path/to/repository
git branch -M main
git push -u origin main
# First, make sure to checkout the branch you want to branch off of
git checkout [original-branch-name]
# Second, make sure that this local branch is updated from the remote branch
git pull
# Third, create your new branch off of this original branch
git checkout -b [new-branch-name]
# Finally, create this upstream branch on the remote origin
git push -u origin [new-branch-name]
When you are typically writing code, make sure to add and commit your changes often, labeling the commit with a message that concisely describes the change or progress in the commit. Generally, each commits should not be over 100 lines of code. Finally, you should push your code to the remote origin at least once a day to save your progress. When there are significant changes that need to be merged into the original branch, you can then create a Pull Request under the Pull Requests tab on the repository on github.
# After writing changes to your file, add it to be staged
git add [file-name]
# Then, commit your changes
git commit -m "Write a short, concise description"
# After a couple of hours, or at the end of the day
git push
# If necessary, then go to the web portal on github and create a PR.