Lecture 06 - More Git and GitHub
18 September, 2024
brew install git
)git config --global user.name "Your Name"
git config --global user.email your@email.com
init
(ialising) repositoriesadd
and commit
changesgit log
git checkout
to go back in timegit status
Today 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 push
pull
changes, use the command git pull
my-project
local repositorygit log
push
our changes to a remote repository on GitHub+
sign on the top right cornerNew repository
my-project
Create repository
push
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 master
git push -u origin master
: pushes the changes to the remote repositorymain
not master
master
to main
. More here.push
further changes to the remote repository, you just repeat the process:
git add file-name
git 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 pull
git 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 mergetool
master
(or main
) branch is the default branch in Git on your computer and on GitHubmaster
branchgit branch branch-name
git checkout branch-name
git switch branch-name
if you have Git 2.23 or latergit checkout -b branch-name
master
branchfeature-1
git checkout -b feature-1
feature-1.txt
to the new branch
echo "This is feature 1" > feature-1.txt
add
, 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 master
git merge feature-1
git push
Done! 🎉 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 clone https://github.com/username/repository-name.git
git clone https://github.com/danilofreire/my-project.git
my-project
repository to a different folderFork
button on the top right cornergit clone https://github.com/your-username/repository-name.git
git remote add upstream https://github.com/original-username/original-repository.git
git fetch upstream
git merge upstream/main
(or upstream/master
)git push
Issues
tab on GitHub and then on the New issue
buttonPull requests
tab on GitHub and then on the New pull request
buttonIssues
Pull requests
+
sign on the top right corner of GitHub and then on New gist
your-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 gh
gh repo create my-project
gh repo clone danilofreire/my-project