GitHub HowTo: Basic Functions
The following outlines basic GitHub function to push
and pull
from your repository. It also includes information on creating a new branch and deleting a branch. These commands should be used in line with guidance on GitHub Repo Management.
Pushing local changes to remote
Check which files have been changed.
git status
Stage files that need to be pushed
git add <thisfile>
git add <thatfile>
Push changes to branch named new_feature
git push origin new_feature
Pulling remote changes to local
Pull changes from branch new_feature
into your branch old_feature
git checkout old_feature
git pull new_feature
If you have non-compatible changes in the old_feature
branch, there are two options: 1) ignore local changes and pull remote anyways. This will delete the changes you’ve made to your remote respository.
git reset --hard
git pull
- temporarily stash changes away, pull and reapply changes after.
git stash
git pull
git stash pop
Creating a new branch
This is a two step process.
- Create the branch locally
git checkout -b <newbranch>
- Push the branch to remote
git push -u origin <newbranch>
OR
git push -u origin HEAD
This is a shortcut to push the current branch to a branch of the same name on origin
and track it so that you don’t need to specify origin HEAD
in the future.
Deleting branches
Locally
git branch -d <BranchName>
on GitHub
git push origin --delete <BranchName>