Skip to content

Common Git Workflows

Matt Brown edited this page Jan 14, 2021 · 2 revisions

Setting up global or local author information

Before you're able to commit any changes within a Git directory, you'll need to have configuring your name and email which will be shown in the commit history. With the --global tag, you can set this authorship for all projects; omitting this allows you to set your author info for only the current directory.

git config -l                                  // 1. Check to see your author info for current project.
git config user.name "<your_name_here>"        // 2. Replace everything inside the arrows to set your preferred author name.
git config user.email "<[email protected]>"       // 3. Same as above, but for your preferred author email address.

Contribute solution to project

If you'd like to contribute to the project, ensure that you've already cloned the repo to your machine, then follow the steps below.

git checkout master                            // 1. If necessary, checkout the `master` branch.
git pull                                       // 2. Pull from remote, ensuring you have any and all of the latest changes.
git checkout -b "my_name-3"                    // 3. Create and checkout a new branch with a title corresponding to the target challenge.
...                                            // 4. Open the suite and begin your work.
git add --all                                  // 5. Stage all necessary changes.
git commit -m "brief commit messsage"          // 6. Add brief commit message.
git push --set-upstream origin "my_name-3"     // 7. Push local branch and associated changes to upstream remote branch with matching name.

Stashing and moving your changes after forgetting to start on a new branch

This happens to the best of us: we get focused on our work and immediately begin modifying files on the master branch. Unfortunately, you won't be allowed to push changes to this branch, but you also won't be able to checkout a new branch without cleaning your current working directory. You'll need to stash all changes, checkout a new branch, then apply your stashed changes to the new branch.

git stash -u                                   // 1. Stashes all changes, including untracked changes.
git checkout -b <new_branch_name>              // 2. Creates a new branch with the defined name.
git stash pop                                  // 3. Removes the last stash added to the array and applies it against current working directory.

Solving a merge conflict between your branch and target branch

This can occur when you submit a pull request and someone else's branch with competing changes has been merged before yours.

git checkout my_name-3                         // If necessary, checkout the source branch for your proposed changes.
git pull origin master                         // Fetch and merge changes from the master branch in the remote repo.
...                                            // This will identify the files with conflicts. Open and resolve conflicts manually.
git add --all                                  // Stage your changes.
git commit                                     // Commit longform changes. This will open VIM in your terminal by default.
git push                                       // Push new commit(s) to your remote upstream.