- Status check current branch
- Branch create branch (if req'd)
- Checkout branch
- Add files
- Commit files
- Push files
- Merge branch
Checking status of current branch
git status will show you your current branch and whether or not you are up to date and have changes to commit.
Creating new branches
git branch nameofbranch where nameofbranch is your custom name. This creates a new branch, but doesn't change your pointer
Checking out branch
git checkout nameofbranch changes your HEAD pointer to the new branch
You can do both in one command that uses shorthand:
git checkout -b nameofbranch
git checkout master changes your HEAD pointer back to the main branch and replaces with master branch files
git add -A adds all changed, new, and deleted files.
Note: if you try to do
git add . it will not stage any delete actions.
git add -u does not add any new files, while the
-A flag does both.
git commit -m "Your message for this commit"
git push pushes all the files to the current branch of the repo.
git push -u origin branchname to get remote to track a new local branch
You can bypass the prompt for username and password each time by storing these to your config:
git config credential.helper store git push http://example.com/repo.git $ Username: <type your username> $ Password: <type your password>
Merging your branch
git checkout master
git merge somebranch
This will take all the commits from somebranch and squash them into 1 commit before merging with master.
If you run into merge conflicts, you can run:
git mergetool to see it in a graphic interface, otherwise the files should contain text that indicates conflicts.
git status will check if there are any conflicts.
git commit will finalize the merge if there were conflicts.
git push then you have to push committed files for the merge to complete
Checkout specific commit
Look at the commit history and find the hash (eg. defc9dab3f2614627da2b29fe7dd694fe0571989) and run
git checkout defc9dab3f2614627da2b29fe7dd694fe0571989