Skip to content

Instantly share code, notes, and snippets.

@lindacmsheard
Last active December 3, 2020 20:12
Show Gist options
  • Save lindacmsheard/51e48780256df893c123c36346795902 to your computer and use it in GitHub Desktop.
Save lindacmsheard/51e48780256df893c123c36346795902 to your computer and use it in GitHub Desktop.

Disclaimer: There are many subtleties to using git - this is a very basic workflow. Discuss in your team how you want to work!

Pre-req

This gist assumes that you have authorisation to clone/pull/push from your repo. Either it is public, or you have set up ssh authentication.

Git basics

git clone <http or ssh link from git portal>
# change into the folder that is created as a result of the cloning.
cd <repo name>

Create a working branch for yourself

git checkout -b mybranch

-> this creates a branch as an exact copy of the branch you were on before. For now, this only exists locally on your machine.

Check this with:

git branch

-> this should put a star next to the branch you are in.

Note: Always make sure that you add/commit your own changes (see below) before you attempt to switch branches.

Standard workflow

# make changes in your branch.
git add .          # this stages any file (.) in the current directory
                   # ensure you are in the root of the repo when you do this!
git commit -m 'my commit message for the work I've just done' 
                   # do this often
git push           # the first time, git will tell you to configure the branch in the online version of the repo
                   # - just follow instructions: git push --set-upstream <branchname>

How to get your changes into master (optional)

Use the pull request feature in the github UI once you've pushed to your own branch.

Note: it is best to first get your own working branch fully up to date with what has been happening on master in the meantime (see next). That way, you deal with any merge conflicts first, rather than the person who reviews your pull request later.

How to get any master changes into your working branch

Do this only once you've committed changes to your working branch with the Standard workflow above - check that you're all clear:

git status
-> "nothing to commit, working tree clean"

Then, switch to the master branch

git checkout master    # this switches to your local copy of the master branch (it won't yet know what has happened online)
git pull               # you now have all the latest changes from others in your local copy

see "Dealing with merge conflicts" if you hit any.

Switch back to your working branch and merge master into it

git checkout dev/myname
git merge master -m 'my note about the fact that I'm updating my branch with master'

(optional) push your updated branch to the online repo

git push

or carry on making local changes with the standard workflow above.

See also

Dealing with merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment