Git
Intro
Need help using Git or navigating your computer through command line? You’re in the right place! GitHub provides hosting for software development version control, which is especially useful when you’re working on a team. Without further ado, let’s get started!
Setup
- Make an account on https://github.com/
- Follow the instructures here to download git and configure your GitHub settings
Fundamentals of Command Line
- To see your current directory run
pwd
- To go into a directory run
cd
followed by the directory name - To see the list of files and folders in the current directory, run
ls
- To go up one directory, run
cd ..
- The tab key sometimes helps you auto complete the names of files and folders
Adding a new Git project
- Navigate to a project directory
- Run
git init
- Run
git add .
- Run
git commit -m "your message"
- Run
git push origin branch_name
wherebranch_name
is replaced by your branch, oftentimes master
Committing Changes
- Make sure you are in your project directory
- Run
git add
followed by the name of the files you want to stage and commit. If you would like to stage all modified files, rungit add .
- Run
git commit -m "your message"
- Run
git push origin branch_name
wherebranch_name
is replaced by your branch, oftentimes master
Cloning a GitHub Project on Computer
- Navigate to the project on GitHub
- Click on the Clone or Download button and copy the link
- Navigate to your project directory through command line and run
git clone
followed by the copied URL
Resolving Merge Conflicts
- Sometimes you may be committing changes when your teammate has already modified the codebase. In these cases, you might be notified of a merge conflict when you push in git.
- You will be notified to open up your code editor, where you can decide which lines of code from which version you would like to keep.
- After saving these changes, you can push your changes.
Further Resources
- The Git Documentation provides a complete list of git commands
- This Git cheatsheet is a great summary of the most commonly used commands
- If you have more questions, consult the internet!