Initialize git repository on folder of project
git init
Check current status of projects i.e. files added to project folder
git status
To start tracking changes made to “file.extn”, we need to add it to the staging area (Untracked files will be red color)
git add file.extn
To store our staged changes we run the commit command with a message describing what we've changed
git commit -m "Message / Comments / Details"
We can add all the new files using a wildcard with git add. Don't forget the quotes!
git add ‘*.*’
To browse commits to see what we changed
git log
To push our local repo to the GitHub server we'll need to add a remote repository
git remote add origin https://github.com/*/*.git
The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do
git push -u origin master
Let's pretend some time has passed. We've invited other people to our GitHub project who have pulled your changes, made their own commits, and pushed them.We can check for changes on our GitHub repository and pull down any new changes
git pull origin master
Staged files are files we have told git that are ready to be committed. You can unstage files by
git reset “*.*”
Files can be changed back to how they were at the last commit
git checkout -- file.extension
When developers are working on a feature or bug they'll often create a copy (aka. branch) of their code they can make separate commits to. Then when they're done they can merge this branch back into their main master branch.We want to remove all these pesky octocats, so let's create a branch called clean_up, where we'll do all the work
git branch clean_up
To switch branches using
git checkout clean_up
To merge your changes from the clean_up branch into the master branch
git merge clean_up
To delete a branch
git branch -d clean_up