Managing Project with Git
Remote Repo is the remote GitHub repo Local Repo is the git repo on your computer Working Files is the set of files you view and edit
Workflows
Standard Workflow
This is a typical workflow for a work session. It covers getting updated with te\he latest updates from other contributors, making and testing mods, and pushing to GitHub
The examples here are for a Doc Reviewer to get current Dev updates, make modification, and push to DocReview branch
- Check current branch. Switch to DocReview if needed
- Pull from GitHub
- Merge Dev branch changes into DocReview
- Update files in DocReview branch
- Commit and Push to GitHub on DocReview Branch
- Login to GitHub adn create Pull Request for newly pushed DocReview update
- This will be a request to merge DocReview changes into Dev branch
- Done
some notes:
git branch
to show what branch you are currently ongit fetch
to get an new branched from remote repo into your working repogit checkout '<branch name>'
to switch to branch name. If branch name has different files, they will be pulled into your local repo and working files- Modify files
- Commit and Push modifications...next section
Regular Update of Working Files to GitHub
You will select files to commit to your working repo, then push them to remote repo
for Master, Dev, and DocReview branches, a push will trigger a re-deploy of the site on Netlify
git status
to display modified filesgit add .
to stage all files for commitgit commit -m "commit message"
to commit stages files to local repo with "commit message" attached to each filegit push
to push committed files to remote repo
If you are committing several small updates, you can preform several
add
andcommit
operation, thenpush
later. The history of commits and commit messages will remain separate
Pull Request to Merge Other Branches into Master
For official merges that require review prior to pushing to Master branch, we will use the GutHub Pull Request mechanism to track major updates. Merging into master can be done via command line git commands, Pull Requests communicate the need for review
- Login to (GitHub)[https://github.com/]
- Open Repository
- Click Pull Request
- Click New Pull Request
- Select branches for base and compare
- For Dev merge into Master, base is Master and compare is Dev
- Review modification that will be made to the base branch in this Pull Request
- If everything looks good, click the Create Pull Request button
- On the next screen you can add comments that the admin will review when processing the request
- Click Create Pull Request button
Admin will review request. They may add comments/questions. Eventually, that will pusg
Forgot to Switch to a Branch Before Committing?
git switch '<branch name>'
with switch local repo branch w/o updating the working files
You can now add, commit, etc
Merge Updates Between Branches
In a typical workflow, updated will be committed and pushed to a branch other than master. Once tested, the other branch will be merged into master for deployment
In this example, the user will update Dev branch, then merge into master
- Make updates to Dev branch
- Commit and Push as required
- Test, check, validate Dev branch updates. This will likely include a Pull Request via GitHub
git checkout master
to switch to master branchgit pull
to ensure your local repo has the latest updated from GitHubgit merge Dev
to bring changes from remote repo Dev branch into local repo master branch- fix and conflicts (need to figure this out)
git push
to push local repo master changes to report repo master branch
This can be performed in the reverse order if you need to merge updates in master into Dev
An expected use of this would be to merge Dev or Master changes into DocReview branch to review latest changes. In this case, you would checkout DevReview branch, pull, then merge Dev into it
Random GIT CLI commands
git reset
Unstage all files after a git add
before a commit
git reset path/to/file/file.ext
unstage single file after git add
before a commit
Check effect with
git status
git commit --amend
to modify a mistake in the current commit action
Such as realizing there is a typo in the text
The commit file will open in an editor. Make updates, save, and close. The cli window will show the amend action is complete
Proceed on with
push
if desired
git diff /path/to/file/file.ext
to view changes since last commit
Good way to see what you are about to commit if you forget