Skip to content

Instantly share code, notes, and snippets.

@Geekgineer
Last active February 7, 2020 10:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Geekgineer/8a864794577ca82e48cd6bd3741e0ea8 to your computer and use it in GitHub Desktop.
Save Geekgineer/8a864794577ca82e48cd6bd3741e0ea8 to your computer and use it in GitHub Desktop.
Quick notes for git-github-config

FOR MAKING YOUR OWN Github REPO:

From existing project files 1- On your local project folder ex: open a terminal

$ git init
$ git add --all # in case you wish to add all the files to stage Or you can selectively add files. 
$ git commit -m "Initial comment" # comment 

log to your github account from web browser and Create a new repository with the same name of your project

2- copy the project url and in the terminal of your local project folder

$ git remote add origin https://github.com/<yourusername>/<myproject>.git
$ git push -u origin master

Or create a new repository from the command line

echo "# <myproject> " >> README.md
$ git init
$ git add README.md
$ git commit -m "first commit"
$ git remote add origin https://github.com/<yourusername>/<myproject>.git
$ git push -u origin master

# to save user and pass
$ git config credential.helper store 
$ git config --global credential.helper store

FOR CONTRIBUTING TO OTHER Github REPOS:

1- Fork this repository by clicking on the fork button on the top of repo page. This will create a copy of this repository in your account. Now clone the forked repository to your machine. Go to your GitHub account, open the forked repository, click on the clone button and then click the copy to clipboard icon.

1- Open a terminal and run the following git command:

$ git clone "url you just copied"

2- Change to the repository directory on your computer (if you are not already there): Now create a branch using the git checkout command:

$ git checkout -b <add-your-new-branch-name>

3- Make necessary changes and commit those changes

If you go to the project directory and execute the command

$ git status

you'll see there are changes.

Add those changes to the branch you just created using command:

$ git add  mychangs.md #add 
$ git add  . #add all 

4- Commit your changes

$ git commit -m "my modified version"

Add git repo to another with all commits

$ cd repo2
$ git checkout master
$ git remote add r1remote <url-of-repo1>
$ git fetch r1remote
$ git merge r1remote/master --allow-unrelated-histories
$ git remote rm r1remote

After that repo2/master will contain everything from repo2/master and repo1/master and will also have the history of both of them


Submodules:

linking repos to main repo as subfolder, to copy use subtrees

Add submodule to existing project:

You can add repo1 as a submodule In the mainrepo repository:

$ git pull origin master #get changes if needed <!--  -->
$ git submodule add https://github.com/<user>/repo1 repo1

Joining a project using submodules:

You can use a modified clone command to ensure you download everything, including any submodules:

$ git clone --recursive <project url>

for more : https://github.blog/2016-02-01-working-with-submodules/


clone spicific branch

you can clone specific branch without need to merge it with the repo master by:

$ git clone -b <branch> <remote_repo> 

ex: $ git clone -b betabot https://github.com/Geekgineer/ros-web-gui.git

Add your Github accout cred. to your OS

$ git config --global user.email "myemail"
$ git config --global user.name "myusername"

Reset all change you made after $ git add .

$ git reset HEAD
$ git pull

then add/commit/push as usual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment