Make sure ssh is checked and copy commands from GitHub to add remote repo
to local project
mkdir my-directory-name
cd my-directory-name
touch my-filename
git init
git add -A
git commit -m "My Message"
Create GitHub repo
Make sure ssh is checked and copy commands from GitHub to add remote repo
to local project
Fork project
Choose only main branch or additional topic branches to be forked
Copy ssh url from my repo
Navigate in the command line to where directory will be added
git clone ssh url from my repo
cd my-project-name
cd my-directory-name
touch my-filename
git init
git add -A
git commit -m "My Message"
Create GitHub repo
Make sure ssh is checked and copy commands from GitHub to add remote repo
to local project
Existing projects
git add -A
git commit -m "My Message"
git push origin my-branch-name
Add and commit all changes before switching branches
git add -A
git commit -m "My Message"
git checkout -b my-topic-branch-name
Add and commit all changes before switching branches
git add -A
git commit -m "My Message"
git checkout main
git merge my-topic-branch-name -m "My Message"
Working with a team
Fork project
Choose only main branch or additional topic branches to be forked
Copy ssh url from my repo
Navigate in the command line to where directory will be added
git clone ssh url from my repo
cd my-project-name
Create a topic branch
git checkout -b my-topic-branch-name
Work on the topic branch
git add -A
git commit -m "My Message"
Merge work into main branch
git checkout main
git merge my-topic-branch-name -m "My Message"
Connect to the upstream repo
git remote add upstream ssh url from upstream repo
Fetch from upsteam branch
git fetch upstream
Checkout main branch
git checkout main
Merge upstream main branch into local main branch
git merge upstream/main
Checkout topic branch
git checkout my-topic-branch
Merge main branch into topic branch
git merge main -m "My Message"
git fetch upstream
git checkout main
git merge upstream/main
git checkout my-topic-branch
git merge main -m "My Message"
Work on the topic branch
git add -A
git commit -m "My Message"
Merge work into main branch
git checkout main
git merge my-topic-branch-name -m "My Message"
All code has been added, committed, and merged into the main branch
Push main branch to GitHub remote repo
git push origin main
Issue pull request
Click the "Pull Request" button
Click the "Create Pull Request" button
Click the "New Pull Request" button
Choose which branch you want to compare
Check the git diff to be sure the changes are what you want
Click the "Create Pull Request" button
Troubleshooting
What directory am I in?
pwd
Have my changes been added and committed?
git status
What remote repos have been added to my directory?
git remote -v
Read the error message
Check for a typo
Google the error message
Be very careful if the command is to remove files or folders. Something
removed in the command line is
gone-gone! 😰
Resolve merge conflicts in the text editor
Remove all conflict markers
git add -A
git commit -m "My Message"
If you're working on a topic branch, you can add and commit the changes,
switch to the main branch without merging, and then delete the topic branch. 😄
If you need to remove one or more commits, you can use git reset. Start
by listing the commits so you can see the commit hash. Then reset the Head to the last commit you want to
keep
git log -3
git reset --hard commit hash you want to keep
git push origin my-branch-name --force
Be very careful with git reset and git push --force. These commands
will permanently remove code from the
branch history. 😰 For safety, consider creating a backup branch before using these commands.
There are times you want to save your work without committing it.
Stashing your code helps to keep your commit history clean and relevant.
git stash
Create a separate branch with you stashed code. Also clears your stash
list.