Lecture 06 - More Git and GitHub
brew install git)git config --global user.name "Your Name"git config --global user.email your@email.cominit(ialising) repositoriesadd and commit changesgit loggit checkout to go back in timegit statusToday we will cover
push and pull changes to and from remote repositories.gitignore to avoid tracking certain filesclone and fork repositories on GitHubissues and pull requests on GitHub
add and commit changespush changes to a remote repository (upload)pull changes from a remote repository (download)push changes to a remote repository, use the command git pushpull changes, use the command git pullmy-project local repositorygit logpush our changes to a remote repository on GitHub+ sign on the top right cornerNew repositorymy-projectCreate repositorypush our changes!git remote add origin https://github.com/danilofreire/my-project.git:
remote: tells Git we are adding a remote repositoryadd: adds a new remote repositoryorigin: the name of the remote repositoryhttps://github.com/danilofreire/my-project.git is the URL of the remote repositorygit branch -M master: renames the branch to mastergit push -u origin master: pushes the changes to the remote repositorymain not mastermaster to main. More here.push further changes to the remote repository, you just repeat the process:
git add file-namegit commit -m "Message"git push (no need to add the remote repository again)pull changes from GitHubpull changes from a remote repository, use (you’ve guessed it) the command git pullgit pull is the equivalent of git fetch + git merge
git fetch downloads the changes from the remote repositorygit merge merges the changes with your local repository.gitignore file to ignore certain files and directories.gitignore to our repositoryI will go to my repository on GitHub and click on Add file > Create new file
After adding the file, I will commit the changes
About .gitignore:
*.csv, to ignore all CSV filesdata/secrets.txt
pull the changes to my local computergit pull and the changes will be downloaded and mergedpull the changes to your local computer toogit mergetool to help you resolve the conflict.gitignore file both in my computer and on GitHub, and commit the changes (do not push yet)
To resolve the conflict, you need to open the file in a text editor
You will see the changes from both you and your coauthor (or yourself)
You can choose which changes to keep, or you can keep both changes
After resolving the conflict, you need to add the file and commit the changes
Then you can push the changes to GitHub
The line that starts with <<<<<<< is your changes
======= indicates the end of your changes and the start of your coauthor’s changes
The line that starts with >>>>>>> is the end of the changes from your coauthor and the commit hash
git mergetoolmaster (or main) branch is the default branch in Git on your computer and on GitHubmaster branchgit branch branch-namegit checkout branch-name
git switch branch-name if you have Git 2.23 or latergit checkout -b branch-namemaster branchfeature-1
git checkout -b feature-1feature-1.txt to the new branch
echo "This is feature 1" > feature-1.txtadd, commit, and push the changes to GitHub
git add feature-1.txt && git commit -m "Add feature 1"git push origin feature-1 (you need to push the new branch to GitHub)Now the branch is already on GitHub
Let’s merge the changes to the master branch
git checkout mastergit merge feature-1git pushDone! 🎉 Let’s see what happened
You can delete the branch with git branch -d feature-1
To delete the branch on GitHub, use git push origin --delete feature-1
More about branches here.
git log --oneline (shows abbreviated hashes)git checkout <commit-hash>git checkout -b new-branch <commit-hash>git reset --hard <commit-hash>git status to confirm your statea1b2c3d or full 1a2b3c4d5e6f7g8h9i0j1k2l3m4n5ogit checkout branch-namegit switch -c new-branch <commit-hash> (Git 2.23+)git switch branch-namegit branch -d branch-namemain branch anymore, you can delete it with git branch -D main (-D forces deletion)main with git branch -m mainmain branch to GitHub with git push -u origin maingit clone https://github.com/username/repository-name.git
git clone https://github.com/danilofreire/my-project.gitmy-project repository to a different folderFork button on the top right cornergit clone https://github.com/your-username/repository-name.gitgit remote add upstream https://github.com/original-username/original-repository.gitgit fetch upstreamgit merge upstream/main (or upstream/master)git pushIssues tab on GitHub and then on the New issue buttonPull requests tab on GitHub and then on the New pull request button Issues
Pull requests
+ sign on the top right corner of GitHub and then on New gistyour-username.github.io.html, .css, and .js files to the repositoryhttps://your-username.github.io.yml file with the steps you want to run.yml file
brew install ghgh repo create my-projectgh repo clone danilofreire/my-project