- Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency
- GitHub is a web-based Git repository hosting service, which offers all of the revision control and source code management (SCM) functionality of Git.
Make sure you are in the projects root directory! You can run ls
to make sure.
git init
This should only be run once - this initializes git in your project.git status
This command allows you to check the current status of our project at anytime. It shows what files are being tracked or need to be added to the staging area.git add -A
This adds all files onto staging. You can see for sure by runninggit status
again.git commit -m "initial commit"
This is the standard message for the first commit of a project.
On GitHub click "New Repository" and give the repo a name, good idea to make it the same as your root directory/project name.
Once you click "Create Repository" you can go back to your terminal and run
git remote add origin <your-remote-repo-url>
To check that the project is connected to GitHub you can run git remote
and you should see "origin" this is what the master branch is called on GitHub.
git push origin master
This command sends your commits to GitHub and is the last step for getting a project set up with Git and GitHub.
Once you them make changes it's good to make commits often when you have working code and are building out your project.
git status
git add <file-names>
git commit -m "descriptive message on what the commit accomplishes here if you haven't hit a working stoping point, a work in progress (WIP) commit works too."
git push origin master
- Follow directions found here so you don't have to put your login and password in everytime to make a commit.
git status
Check status of files modified, added, deleted, etc.git logs
A journal that remembers all the changes we've committed so far, in the order we committed them.git stash
Allows you to discard changed files instead of adding them to staging, you can also get them back if you want to come back to them later withgit stash pop
git remote
Checks to see what remotes have access to this repository. You should see origin for github and heroku for if you've connected it there for deployement.
git clone <repo-link>
git remote rm origin
- go to Github and set up your own repo
git remote add origin <your-remote-repo-url>
- on-going git workflow
When collaborating it's common to create branches for features so that git can track who is working on each file.
New branch
git pull origin master
This command pulls down the latest code on the master branch from GitHub.git checkout -b <branch-name-descriptive-of-feature>
Once you are on a branch you would use the on-going git workflow and then push to the branch name. head
is an alias for the head of whatever branch you are currently on.
git push origin <branch-name>
ORgit push origin head
To switch branches
git checkout <branch-name>
Once you push that sends the changes to Github. When you are ready to have your branched changes reviewed and mergedinto the master branch you open a pull request.When you push the terminal output gives you a link to the page on github you can open a pull request from.
Code review occurs at this stage and additional refactoring and changes may occur. When the code is ready to be merged into master, it's time to click "Merge Pull Request" button at the bottom of the pull request page.