25
loading...
This website collects cookies to deliver better user experience
$> git config --global user.name "username"
$> git config --global user.email "[email protected]
ssh-keygen
. If you’re on Windows, the best way to do this is with Git Bash, which should have come with your installation of Git. If not, go back to the download page and download it again. You can find Git Bash by typing bash into your search box and clicking this icon:$> eval `ssh-agent -s`
ssh-agent
are backticks (Shift + ~). If after running this command you see something like “Agent pid 5278”, you’re good to go. If not, please refer to this article on the GitHub docs.ssh-add ~/.ssh/gittutorial
. You will be prompted again for your passphrase, just retype it or press enter if you didn’t make one.cat ~/.ssh/gittutorial.pub
and copy the output (if you have a program called clip installed, you can run clip < ~/.ssh/gittutorial.pub
). Back in your browser, paste the contents into the “key” field. Check carefully for an errant line break, if your key ends with your email, but your cursor is on the next line, hit backspace to get rid of that character.$> git clone [email protected]:erik-whiting/ecs-git-tutorial.git
dir
or ls
to see the contents and notice that there’s now a folder called ecs-git-tutorial
. Go ahead and cd
into it and run ls
again. Notice that the README is in there. That’s the same README you see on your repository’s homepage on GitHub. We’ve successfully cloned the repo onto our local machine!git clone
.Hi, I'm a text file
git add tutorial.txt
and make a simple commit, something like git commit -m "First commit"
. Now we’ve got this tutorial.txt file and commit history on our local computer only. We now want to publish our changes by pushing them. To push your changes to the repo, run the following command:$> git push
$> git checkout -b edit-tutorial.txt
git status
to make sure you see that tutorial.txt has been modified. Go ahead and commit these changes with:$> git commit -am "Add line to tutorial.txt"
git push
. Notice that we get an error that saysfatal: The current branch edit-tutorial.txt has no upstream branch. To push the current branch and set the remote as upstream, use
git push –set-upstream origin edit-tutorial.txt
main
. We have to create the branch on GitHub in order to publish our local branch. Doing so is as easy as running the command suggested by the error message though, so simply run:$> git push --set-upstream origin edit-tutorial.txt
tutorial.txt
file. You should now see the line “This line was added from the edit-tutorial.txt branch” we just added. We’ve successfully merged our changes!$> git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'
main
. What gives?main
branch with the remote main
branch on GitHub. First, we can sync our data by running git fetch
which will update our local repository with notifications of any changes made to remote (NOTE! The fetch
command does not update your local branches, it only updates your repository with current information about the repo like PRs made or if your branches are behind).git status
and you should now see a message about being behind by a few commits. Mine looks like this after running the fetch
command:$> git status
On branch main
Your branch is behind by 'origin/main' by 2 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
main
branch, we simply have to run git pull
. Run that in your terminal and open the tutorial.txt file again. You should notice this time that the “This line was added from the edit-tutorial.txt branch” line is in there now.