/
git_sheet.py
79 lines (54 loc) · 2.62 KB
/
git_sheet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# https://guides.github.com/introduction/git-handbook/
# https://guides.github.com/activities/hello-world/
# =========================================================================
# GitHub and the command line
# For developers new to the command line, the GitHub Training team has put together a series of tutorials on Git commands to guide the way. Sometimes, a series of commands can paint a picture of how to use Git:
Example: Contribute to an existing repository
# download a repository on GitHub.com to our machine
git clone https://github.com/me/repo.git
# change into the `repo` directory
cd repo
# create a new branch to store any new changes
git branch my-branch
# switch to that branch (line of development)
git checkout my-branch
# make changes, for example, edit `file1.md` and `file2.md` using the text editor
# stage the changed files
git add file1.md file2.md
# take a snapshot of the staging area (anything that's been added)
git commit -m "my snapshot"
# push changes to github
git push --set-upstream origin my-branch
# =========================================================================
# Example: Start a new repository and publish it to GitHub
# First, you will need to create a new repository on GitHub. You can learn how to create a new repository in our Hello World guide. Do not initialize the repository with a README, .gitignore or License. This empty repository will await your code.
# create a new directory, and initialize it with git-specific functions
git init my-repo
# change into the `my-repo` directory
cd my-repo
# create the first file in the project
touch README.md
# git isn't aware of the file, stage it
git add README.md
# take a snapshot of the staging area
git commit -m "add README to initial commit"
# provide the path for the repository you created on github
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
# push changes to github
git push --set-upstream origin master
# =========================================================================
# Example: contribute to an existing branch on GitHub
# assumption: a project called `repo` already exists on the machine, and a new branch has been pushed to GitHub.com since the last time changes were made locally
# change into the `repo` directory
cd repo
# update all remote tracking branches, and the currently checked out branch
git pull
# change into the existing branch called `feature-a`
git checkout feature-a
# make changes, for example, edit `file1.md` using the text editor
# stage the changed file
git add file1.md
# take a snapshot of the staging area
git commit -m "edit file1"
# push changes to github
git push